Android 我的AndEngine onLoadResources()似乎效率不高
我正在使用AndEngine创建一个实时壁纸。但是,在我的onLoadResources()方法中,我当前正在加载3种不同的纹理:Android 我的AndEngine onLoadResources()似乎效率不高,android,andengine,live-wallpaper,Android,Andengine,Live Wallpaper,我正在使用AndEngine创建一个实时壁纸。但是,在我的onLoadResources()方法中,我当前正在加载3种不同的纹理: @Override public void onLoadResources() { prefs = PhysicsWallpaperActivity.this.getSharedPreferences(SHARED_PREFS_NAME, 0); prefs.registerOnSharedPreferenceChangeListener(this)
@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);
}
我觉得这不是最有效的方法。但是,如果我的所有BitMapTextureLastExtureRegionFactory的“图像”都指向一个BitMapTextureAlas,并且这些“图像”位于相同的坐标,那么即使我只调用其中的一个,这些图像也会相互叠加加载
问题的一个例子如下:
@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);
}
^我希望使用这样的代码,因为它看起来更有效,但是“image1”和“image2”会自动加载到彼此的顶部,即使我只调用其中的一个
我这样做对吗?还是有更有效的方法?你的纹理太大了!你确定你需要这么大吗?你的纹理可以包含多个资源。把它想象成一张雪碧床单。或者像把照片粘在一张大白纸上。您不需要为每个纹理区域创建新纹理。例如: 假设你有一张250x250像素的恒星图像和一张100x100像素的宇宙飞船图像。你可以把这两个放在一个测量512x256的纹理上。 在0,0处为星形(250x250)创建纹理区域。 然后在251,0处为宇宙飞船创建第二个纹理区域 在这种情况下,如果其他图像足够小,可以放在太空船上,那么还有一些剩余区域。下图显示了如果你能在内存中看到纹理,它会是什么样子
希望这有帮助。啊,谢谢你,我忘了这些。你会推荐1024x1024吗?是的,1024x1024应该是最大值,以确保与所有设备的兼容性。谢谢,这对我们很有帮助。虽然我正在创建的图像占据了整个屏幕,所以我认为它们必须是那个尺寸。但是onLoadResources()仅在第一次创建墙纸时调用。。对吗?如果活动被系统终止,也可以在onResume()上调用它-如果你有巨大的纹理,这有点可能。使你的纹理尽可能小,你可以摆脱。试着以半分辨率制作一个集合,让开放式GL在屏幕上显示。你可能会发现它看起来很棒。