5

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?

Genaut
  • 1,810
  • 2
  • 29
  • 60
  • Which GLES are you using? GLES2? I have onCreateResources() in GLES2. I have no idea why Nicolas Gramlich decided to rename key functions like this, and why he created an engine/library without documentation. Can anybody provide help? – Shailen Sep 21 '12 at 12:33
  • 1
    Who knows what he was thinking when it came to documentation, and god forbid you say anything about this over on the andengine forums, if you do you get told that you should just read the source code and work it out, i mean thats all well and good but there isnt even any comments in the source code for the thing. Its a shame really it is a nice little open source engine, just my two cents :D – Spider Oct 09 '12 at 23:03
  • I am also facing similar issue ... I am unable to set my background ... here is the code ..menuBackgroundTexture = new BitmapTextureAtlas(null, 2*CAMERA_WIDTH, 2*CAMERA_HEIGHT, TextureOptions.DEFAULT); menuBgTexture = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.menuBackgroundTexture, this, "land.png", 0, 0); SpriteBackground bg = new SpriteBackground(new Sprite(0, 0, menuBgTexture,this.getVertexBufferObjectManager())); mScene.setBackground(bg);.... can anyone help me? – Rahul Jul 05 '14 at 17:54

2 Answers2

2

for the VBOManager object, use

this.getVertexBufferObjectManager();
jmroyalty
  • 2,527
  • 1
  • 17
  • 21
  • Thanks! works fine :) The bg image not fill all space on the screen, I have to add anything? – Genaut Jun 07 '12 at 15:19
  • how are you initializing the Engine? what size, what ResolutionPolicy – jmroyalty Jun 07 '12 at 16:53
  • Well, I'm starting with the engine now, so I don't know much about it yet, but my "onCreateEngine" is: camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT); EngineOptions engineOptions = new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, new FillResolutionPolicy(), camera); private final int CAMERA_WIDTH = 720; private final int CAMERA_HEIGHT = 480; My image size is 320x480 – Genaut Jun 07 '12 at 21:27
  • I guess it filled the 480 and centered the 320 in the 720, but what do you want to happen? can your background be repeated? – jmroyalty Jun 07 '12 at 22:13
  • Yeah, I set the camera the same size and all woks fine, Thanks Again – Genaut Jun 09 '12 at 16:01
1

I also had the same issue with my game. The solution is to have a background image that is of the same dimensions as the camera. For example, if your camera is 800X480, the image should be of the same dimensions as well. Also, make the dimensions of the BitmapTextureAtlas factors of two. In your case, it should be 512px by 512 px. Hope that helps.

Cheers!!

Muiruri
  • 45
  • 6