Domanda

sto usando AndEngine per creare una carta da parati dal vivo. Tuttavia, nelle mie onLoadResources () metodo Attualmente sto caricando 3 strutture differenti:

@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);               

}

Mi sento come se questo non è il modo più efficace per farlo. Ma se ho tutti i miei BitmapTextureAtlasTextureRegionFactorys 'immagini' che punta a un solo BitmapTextureAtlas, e quelle 'immagini' sono allo stesso coordinate, le immagini verranno caricate insieme in cima a vicenda, anche se solo io chiamo uno di loro.

Un esempio del problema è qui:

    @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);               

}

^ mi sarebbe piaciuto di utilizzare il codice come questo perché sembra più efficiente, ma 'Image1' e 'image2' caricare automaticamente uno sopra l'altro, anche se solo io chiamo uno di loro.

sto facendo questo il modo giusto? O c'è un modo più efficiente?

È stato utile?

Soluzione

I tuoi texture può contenere più di una risorsa. Pensate a come un foglio sprite. o come incollaggio foto ad un grande foglio di carta bianca. non hai bisogno di una nuova texture per ogni regione texture. Per esempio: Diciamo che avete un immagine della stella, che è un'immagine nave spaziale che è 100x100 pixel 250x250 pixel e. Si potrebbe mettere entrambi questi su una texture che misura 512x256. Si crea una regione texture per la stella (250x250) a 0, 0. Quindi creare una seconda regione trama per il navicella spaziale in 251, 0.

In questo scenario c'è ancora qualche zona rimasto per altre immagini soffiano l'astronave, se sono piccoli abbastanza da contenere. L'immagine sotto mostra come la vostra struttura apparirebbe se si poteva vedere in memoria.

texture con due risorse aggiunto

Spero che questo aiuti.

Altri suggerimenti

I tuoi texture sono enormi! Sei molto sicuro che hai bisogno di loro così grande?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top