【问题标题】:How can i change a background texture on AndEngine?如何更改 AndEngine 上的背景纹理?
【发布时间】:2013-02-07 16:30:50
【问题描述】:

我有一个背景纹理,并想将其更改为其他背景纹理。我已经阅读并测试了一些关于背景纹理的示例,但第二个背景没有显示。

这是我用来尝试更改的最后一个代码...有人可以帮忙吗? 谢谢

    Scene scene1 = new Scene();
    ITexture backgroundTexture1 = null;
    try {
        backgroundTexture1 = new BitmapTexture(this.getTextureManager(), new IInputStreamOpener() {
            @Override
            public InputStream open() throws IOException {
                return getAssets().open("gfx/crackedscreen.png");
            }
        });
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    backgroundTexture1.load();
    this.mBackgroundTextureRegion1 = TextureRegionFactory.extractFromTexture(backgroundTexture1);
    Sprite backgroundSprite = new Sprite(0, 0, this.mBackgroundTextureRegion1, getVertexBufferObjectManager());
    scene1.attachChild(backgroundSprite);
    scene1.setBackgroundEnabled(true);
    return scene1;

【问题讨论】:

  • 只改变加载到这个区域的纹理mBackgroundTextureRegion1
  • 我已更新代码以加载新纹理,但没有任何变化。仍然显示第一个背景。谢谢。

标签: android background andengine


【解决方案1】:

我在使用 Sprites 更改背景时也遇到了一些麻烦。我终于成功使用了 SpriteBackground。只需从您的 Sprite 创建一个:

SpriteBackground background = new SpriteBackground(backgroundSprite);

不调用attachchild,而是调用setBackground:

scene.setBackground(background);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-16
    • 1970-01-01
    • 2016-11-07
    • 1970-01-01
    • 1970-01-01
    • 2018-08-14
    • 2020-05-04
    • 1970-01-01
    相关资源
    最近更新 更多