2012-06-07 16 views
5

Quiero establecer el fondo de mi escena, pero no sé cómo! Había leído mucho sobre esto, pero no puedo hacer que esto funcione. Es mi comienzo con Andengine, y es difícil encontrar información precisa para mi problema, todo es subjetivo.Añadir fondo a la escena Andengine Android

Bueno, he implementado la pantalla de bienvenida en una escena, y mientras cargo todos los recursos y escenas. (https://sites.google.com/site/matimdevelopment/splash-screen---easy-way)

Luego, tengo que establecer un fondo para mi menúScene, creo que necesito una TextureRegion y una BitmapTextureAtlas para crear cada backgroud. Hago esto:

texturas declaró:

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

Recursos vacío y la carga escenas (Se les llama por onPopulateScene cuando termina Splash)

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(); 
} 

de Recursos carga no muestra error, pero loadScenes, Línea : SpriteBackground bg = new SpriteBackground (nuevo Sprite (centerX, centerY, menuBgTexture));

Me dice que tengo que establecer un nuevo atributo (ISpriteVertexBufferObject), bueno, ¿qué es esto?

+0

¿Qué GLES estás usando? GLES2? Tengo onCreateResources() en GLES2. No tengo idea de por qué Nicolas Gramlich decidió renombrar funciones clave como esta y por qué creó un motor/biblioteca sin documentación. ¿Alguien puede ayudar? – shailenTJ

+1

Quién sabe lo que estaba pensando cuando se trata de documentación, y Dios no quiera que digas nada sobre esto en los foros de andengine, si lo haces te dicen que solo debes leer el código fuente y resolverlo, quiero decir que eso es todo bien y bien, pero ni siquiera hay ningún comentario en el código fuente de la cosa. Es una pena realmente es un pequeño y agradable motor de código abierto, solo mis dos centavos: D – Spider

+0

También estoy enfrentando un problema similar ... No puedo establecer mi fondo ... aquí está el código ..menuBackgroundTexture = new BitmapTextureAtlas (null, 2 * CAMERA_WIDTH, 2 * CAMERA_HEIGHT, TextureOptions.DEFAULT); \t menuBgTexture = BitmapTextureAtlasTextureRegionFactory.createFromAsset (this.menuBackgroundTexture, this, "land.png", 0, 0); \t \t SpriteBackground bg = new SpriteBackground (nuevo Sprite (0, 0, menuBgTexture, this.getVertexBufferObjectManager())); \t \t mScene.setBackground (bg); .... ¿alguien puede ayudarme? – Rahul

Respuesta

2

para el objeto VBOManager, utilice

this.getVertexBufferObjectManager(); 
+0

¡Gracias! funciona bien :) La imagen bg no llena todo el espacio en la pantalla, ¿tengo que agregar algo? – Genaut

+0

¿cómo está inicializando el motor? qué tamaño, qué ResolutionPolicy – jmroyalty

+0

Bueno, ahora estoy empezando con el motor, así que no sé mucho al respecto todavía, pero mi "onCreateEngine" es: camera = new Camera (0, 0, CAMERA_WIDTH, CAMERA_HEIGHT); EngineOptions engineOptions = new EngineOptions (true, ScreenOrientation.LANDSCAPE_FIXED, nueva FillResolutionPolicy(), cámara); private final int CAMERA_WIDTH = 720; private final int CAMERA_HEIGHT = 480; Mi tamaño de imagen es 320x480 – Genaut

1

También tuve el mismo problema con mi juego. La solución es tener una imagen de fondo que tenga las mismas dimensiones que la cámara. Por ejemplo, si su cámara es 800X480, la imagen también debe tener las mismas dimensiones. Además, haga las dimensiones de los factores BitmapTextureAtlas de dos. En tu caso, debe ser de 512 px por 512 px. Espero que ayude.

¡Salud!

Cuestiones relacionadas