zoukankan      html  css  js  c++  java
  • Andengine 背景自动移动AutoParallaxBackground 1

    在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)构建一个背景实体,第一个参数表示视差移动的因数,为负表示相对前景
    或英雄反向移动。绝对值越大移动的越快,也就说这个因数是靠前的背景比后面的背景的绝对值大。

        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; }
  • 相关阅读:
    【OpenJudge 2.5-1792】这绝壁是一道玄学题!【DFS】
    【BZOJ1034】省队选手不务正业打泡泡堂(我也不知道是啥算法)
    文件操作的常用方法和使用
    数据类型所有方法和使用整理之------字典
    数据类型所有方法和使用整理之------列表
    用类的内置方法实现类型检查
    类的内置方法及描述符
    用python实现MRO算法
    RHEL6.5 DHCP服务器搭建
    Python之禅 吾心笃定
  • 原文地址:https://www.cnblogs.com/wzachenjian/p/3571012.html
Copyright © 2011-2022 走看看