Pregunta

Estoy usando AndEngine para crear un fondo de pantalla en vivo. Sin embargo, en mi método OnloadResources () estoy cargando 3 texturas diferentes:

@Override
public void onLoadResources() {
    prefs = PhysicsWallpaperActivity.this.getSharedPreferences(SHARED_PREFS_NAME, 0);
    prefs.registerOnSharedPreferenceChangeListener(this);
    this.mAutoParallaxBackgroundTexture = new BitmapTextureAtlas(2048, 2048, TextureOptions.DEFAULT);
    this.mAutoParallaxImage1Texture = new BitmapTextureAtlas(2048, 2048, TextureOptions.DEFAULT);
    this.mAutoParallaxImage2Texture = new BitmapTextureAtlas(2048, 2048, TextureOptions.DEFAULT);

    BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
    this.mParallaxLayerBackground = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mAutoParallaxBackgroundTexture, this, "background.jpg", 0, 0);
    this.mParallaxLayerImage1 = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mAutoParallaxImage1Texture, this, "image1.jpg", 0, 0);
    this.mParallaxLayerImage2 = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mAutoParallaxImage2Texture, this, "image2.png", 0, 800);

    this.mEngine.getTextureManager().loadTexture(this.mAutoParallaxBackgroundTexture);  
    this.mEngine.getTextureManager().loadTexture(this.mAutoParallaxImage1Texture);               
    this.mEngine.getTextureManager().loadTexture(this.mAutoParallaxImag2Texture);               

}

Siento que esta no es la forma más eficiente de hacer esto. Pero si tengo todas mis 'imágenes' de maptextuteatheateathextextureRegionsfactorys que apuntan a solo un bitmaptextureatlas, y esas 'imágenes' están en las mismas coordenadas, las imágenes se cargarán juntas, incluso si solo llamo 1 de ellas.

Un ejemplo del problema está aquí:

    @Override
 public void onLoadResources() {
    prefs = PhysicsWallpaperActivity.this.getSharedPreferences(SHARED_PREFS_NAME, 0);
    prefs.registerOnSharedPreferenceChangeListener(this);
    this.mAutoParallaxBackgroundTexture = new BitmapTextureAtlas(2048, 2048, TextureOptions.DEFAULT);

    BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
    this.mParallaxLayerBackground = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mAutoParallaxBackgroundTexture, this, "background.jpg", 0, 0);
    this.mParallaxLayerImage1 = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mAutoParallaxBackgroundTexture, this, "image1.jpg", 0, 0;
    this.mParallaxLayerImage2 = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mAutoParallaxBackgroundTexture, this, "image2.png", 0, 800);

    this.mEngine.getTextureManager().loadTexture(this.mAutoParallaxBackgroundTexture);               

}

^ Me hubiera gustado usar el código así porque parece más eficiente, pero 'Image1' y 'Image2' se cargan automáticamente uno encima del otro, incluso si solo llamo a 1 de ellos.

¿Estoy haciendo esto de la manera correcta? ¿O hay una manera más eficiente?

¿Fue útil?

Solución

Sus texturas pueden contener más de un recurso. Piense en ello como una hoja de sprites. O como pegar fotos a una gran hoja de papel blanca. No necesita una nueva textura para cada región de textura. Por ejemplo: digamos que tiene una imagen de estrella, es decir, 250x250 píxeles y una imagen de nave espacial que es de 100x100 píxeles. Podrías poner ambos en una textura que mida 512x256. Creas una región de textura para la estrella (250x250) a 0, 0. luego crea una segunda región de textura para la nave espacial en 251, 0.

En ese escenario, todavía hay un área sobrante para otras imágenes, explotan la nave espacial, si son lo suficientemente pequeñas como para encajar. La imagen a continuación muestra cómo se vería su textura si pudiera verla en la memoria.

texture with two resources added

Espero que esto ayude.

Otros consejos

¡Tus texturas son enormes! ¿Estás muy seguro de que los necesitas tan grandes?

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top