我使用AndEngine創建動態壁紙。然而,在我onLoadResources()方法,我現在裝3個不同質地:我的AndEngine onLoadResources()似乎效率不高
@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);
}
我覺得這是不是這樣做的最有效方法。但是,如果我將所有BitmapTextureAtlasTextureRegionFactorys'圖像'指向一個BitmapTextureAtlas,並且這些'圖像'處於相同座標,則即使只調用其中一個圖像,圖像也會一起加載。
問題的一個例子是在這裏:
@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);
}
^我也喜歡使用這樣的代碼,因爲它似乎更有效,但「圖像1」和「圖像2」上的每個頂部自動加載其他即使我只打1個。
我這樣做是正確的嗎?還是有更高效的方法?
謝謝,這有助於很多。雖然我創建的圖片佔據了整個屏幕,所以我認爲它們必須達到這個尺寸。但onLoadResources()僅在第一次創建壁紙時調用..對嗎? – MJ93
如果活動被系統殺死,它也可以在onResume()上調用 - 如果你有巨大的紋理,這很可能。讓你的紋理儘可能的小,你可以擺脫。嘗試製作一個半分辨率的設置,並讓AndEngine中的開放式GL將其解決。 YOu可能會覺得它看起來不錯。 –