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; }
  • 相关阅读:
    Web前端开发资源集锦
    刮刮卡效果
    html5游戏驴子跳
    Bootstrap3实现的响应式幻灯滑动效果个人作品集/博客网站模板
    40款免费社交图标素材
    移动端的推拉效果导航菜单-支持响应式及其多层菜单
    通过HTML5 Visibility API检测页面活动状态
    HTML5游戏开发引擎Pixi.js新手入门讲解
    滚动触发的翻转式文字引用效果
    11个实用的CSS学习工具
  • 原文地址:https://www.cnblogs.com/wzachenjian/p/3571012.html
Copyright © 2011-2022 走看看