viernes, 3 de agosto de 2012

Tutorial Sprite Background AndEngine GLES 2.0

Colocar un Sprite de fondo se hace de la misma manera que colocar un Sprite en la pantalla. Casi todos los pasos son iguales al tutorial anterior si os dejo pegado el código y solo explico lo que es diferente.

  1. public class Main extends SimpleBaseGameActivity {
  2. private static final int CAMERA_WIDTH = 800;
  3. private static final int CAMERA_HEIGHT = 480;
  4. private ITextureRegion mFondoTextureRegion;
  5. private BitmapTextureAtlas mFondoTextureAtlas;
  6. public EngineOptions onCreateEngineOptions() {
  7. final Camera camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
  8. return new EngineOptions(true, ScreenOrientation.LANDSCAPE_SENSOR, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), camera);
  9. }
  10. public void onCreateResources() {
  11. BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
  12. this.mFondoTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 1500, 1500);
  13. this.mFondoTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mFondoTextureAtlas, this, "fondo.png", 0, 0);
  14. this.mFondoTextureAtlas.load();
  15. }



Lo único que cambia es en onCreateScene(). Definimos nuestra escena como antes y
,definimos el sprite de fondo e introducimos setBackground(). Así quedaría onCreateScene():


  1. public Scene onCreateScene() {
  2. final Scene escena = new Scene();
  3. final Sprite fondo = new Sprite(0, 0, this.mFondoTextureRegion, this.getVertexBufferObjectManager());
  4. scene.setBackground(new SpriteBackground(fondo));    
  5. return scene;
  6. }
Y con esto ya tenemos nuestra imagen en el fondo.

No hay comentarios:

Publicar un comentario