【问题标题】:Creating a parallax background创建视差背景
【发布时间】:2014-03-08 17:11:17
【问题描述】:

我正在尝试在我的游戏中添加移动背景,但我无法弄清楚。我现在使用的当前代码是这个,它的作用是设置一个带有移动云的灰色背景颜色。这是在我的 GameScene.java 中

    private void createBackground() {
    pb = new ParallaxBackground(0.53f, 0.53f, 0.53f); //Background color
    Entity clouds = new Rectangle(0, 0, 1000, 800, vbom);
    clouds.setAnchorCenter(0, 0);
    clouds.setAlpha(0f);
    clouds.attachChild(new Sprite(100, 500, res.cloudRegion, vbom));
    clouds.attachChild(new Sprite(300, 700, res.cloudRegion, vbom));

    clouds.attachChild(new Sprite(500, 600, res.cloudRegion, vbom));
    clouds.attachChild(new Sprite(800, 730, res.cloudRegion, vbom));

    ParallaxEntity pe = new ParallaxEntity(-0.2f, clouds);
    pb.attachParallaxEntity(pe);
    setBackground(pb);
}

从 ResourceManager.java 调用 cloudRegion

cloudRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            gameObjectsAtlas, activity.getAssets(), "cloud.png");

我已经为此困扰了好几天,所以如果你能提供帮助,那就太好了;谢谢。

【问题讨论】:

  • 将云作为 ParallaxEntity 添加到您的 ParallaxBackground。试试这个

标签: java android opengl-es-2.0 andengine


【解决方案1】:

你想要的是 AutoParallaxBackground - https://github.com/nicolasgramlich/AndEngine/blob/720897f99d2c56ba357e8fe361454bd8d88c37ed/src/org/andengine/entity/scene/background/AutoParallaxBackground.java

pb = new AutoParallaxBackground(0.53f, 0.53f, 0.53f, 15);

这应该就是您需要更改的所有内容,因为其他一切看起来都很好。

我希望这会有所帮助(尽管可能为时已晚)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-19
    • 2015-04-30
    • 1970-01-01
    • 1970-01-01
    • 2022-01-20
    • 2021-03-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多