user1847912
user1847912

Reputation: 25

How can i change a background texture on AndEngine?

I have a background texture, and want to change it to other background texture. I have read and test some samples about backgrounds textures, but the the second background don´t show.

This is the last code i used to try to change...anybody can help ? thanks

    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;

Upvotes: 1

Views: 915

Answers (1)

eculeus
eculeus

Reputation: 1270

I had some trouble changing backgrounds using Sprites too. I finally had success using SpriteBackground. Simply create one from your Sprite:

SpriteBackground background = new SpriteBackground(backgroundSprite);

Instead of calling attachchild, call setBackground:

scene.setBackground(background);

Upvotes: 2

Related Questions