Add background to Andengine scene Android

Genaut picture Genaut · Jun 7, 2012 · Viewed 8.6k times · Source

I wanna set My Scene Background but I don't know how! I had read a lot about this, but I can't make this works. Is my start with Andengine, and is hard found precise information for my problem, all is subjective.

Well, I have implemented the splash screen in a scene, and while load all resources and scenes. (https://sites.google.com/site/matimdevelopment/splash-screen---easy-way)

Then, I have to set a Background to my menuScene, I think that I need a TextureRegion and a BitmapTextureAtlas to create each backgroud. I do this:

Declared textures:

    //Fondo escenas
private TextureRegion menuBgTexture;
private BitmapTextureAtlas menuBackgroundTexture;

Load Resources and Load scenes (They are called by onPopulateScene when Splash ends)

public void loadResources() 
{
    //FondoMenu
    menuBackgroundTexture = new BitmapTextureAtlas(null, 480, 320, TextureOptions.DEFAULT);
    menuBgTexture = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.menuBackgroundTexture, this, "menubg.png", 0, 0);
    //Cargamos los fondos
    mEngine.getTextureManager().loadTexture(this.menuBackgroundTexture);

}

private void loadScenes()
{
    //Menú
    menuScene = new Scene();
    final float centerX = (CAMERA_WIDTH - menuBgTexture.getWidth()) / 2;
    final float centerY = (CAMERA_HEIGHT - menuBgTexture.getHeight()) / 2;
    SpriteBackground bg = new SpriteBackground(new Sprite(centerX, centerY, menuBgTexture));
    menuScene.setBackground(bg);
    //menuScene.setBackground(new Background(50, 0, 0));
    //Options
    optionsScene = new Scene();
    //Juego
    gameScene = new Scene();
    //Pausa
    pauseScene = new Scene();
    //Gameover
    gameOverScene = new Scene();
}

load Resource not shows error, but loadScenes, Line: SpriteBackground bg = new SpriteBackground(new Sprite(centerX, centerY, menuBgTexture));

Says me that I have to set a new attribute (ISpriteVertexBufferObject), well, what is this?

Answer

jmroyalty picture jmroyalty · Jun 7, 2012

for the VBOManager object, use

this.getVertexBufferObjectManager();