我使用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可能会觉得它看起来不错。 –