首页 > 移动平台 > 详细

Andengine 背景自动移动AutoParallaxBackground 1

时间:2014-02-28 04:11:03      阅读:531      评论:0      收藏:0      [点我收藏+]

在Andengine 用AutoParallaxBackground实现这个效果。

new AutoParallaxBackground(final float pRed, final float pGreen,final float pBlue,  背景颜色的三个值 红绿篮      

final float pParallaxChangePerSecond) 图片移动的速度

AutoParallaxBackground(float pRed, float pGreen, float pBlue, float pParallaxChangePerSecond)
ParallaxBackground.attachParallaxEntity(ParallaxEntity pParallaxEntity)往视差背景对象中加入一个背景实体
ParallaxEntity(float pParallaxFactor, Shape pShape)构建一个背景实体,第一个参数表示视差移动的因数,为负表示相对前景
或英雄反向移动。绝对值越大移动的越快,也就说这个因数是靠前的背景比后面的背景的绝对值大。

 

bubuko.com,布布扣
    private BitmapTextureAtlas    mAutoParallaxBackgroundTexture;
    public ITextureRegion mParallaxLayerBack;
    private ITextureRegion mParallaxLayerMid;
    private ITextureRegion mParallaxLayerFront;



private void initTexture() {
        this.mAutoParallaxBackgroundTexture = new BitmapTextureAtlas(
                mContext.getTextureManager(), 1024, 1024);
        this.mParallaxLayerFront = BitmapTextureAtlasTextureRegionFactory
                .createFromAsset(this.mAutoParallaxBackgroundTexture, mContext,
                        "parallax_background_layer_front.png", 0, 0);
        this.mParallaxLayerBack = BitmapTextureAtlasTextureRegionFactory
                .createFromAsset(this.mAutoParallaxBackgroundTexture, mContext,
                        "parallax_background_layer_back.png", 0, 188);
        this.mParallaxLayerMid = BitmapTextureAtlasTextureRegionFactory
                .createFromAsset(this.mAutoParallaxBackgroundTexture, mContext,
                        "parallax_background_layer_mid.png", 0, 669);
        this.mAutoParallaxBackgroundTexture.load();

game_scene=initScene(); }
private Scene initScene() { Scene pScene = new Scene(); mContext.getEngine().registerUpdateHandler(new FPSLogger()); final AutoParallaxBackground autoParallaxBackground = new AutoParallaxBackground( 0, 0, 0, 5); final VertexBufferObjectManager vertexBufferObjectManager = mContext .getVertexBufferObjectManager(); autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(0.0f, new Sprite(0, BaseData.CAMERA_HEIGHT - this.mParallaxLayerBack.getHeight(), this.mParallaxLayerBack, vertexBufferObjectManager))); autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(-5.0f, new Sprite(0, 80, this.mParallaxLayerMid, vertexBufferObjectManager))); autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(-10.0f, new Sprite(0, BaseData.CAMERA_HEIGHT - this.mParallaxLayerFront.getHeight(), this.mParallaxLayerFront, vertexBufferObjectManager))); // 将这个背景设为场景的背 pScene.setBackground(autoParallaxBackground); return pScene; }
bubuko.com,布布扣

Andengine 背景自动移动AutoParallaxBackground 1,布布扣,bubuko.com

Andengine 背景自动移动AutoParallaxBackground 1

原文:http://www.cnblogs.com/wzachenjian/p/3571012.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!