我的和引擎的OnloadResources()似乎不是高效的
-
26-10-2019 - |
题
我正在使用和引擎来创建实时墙纸。但是,在我的OnloadResources()方法中,我目前正在加载3种不同的纹理:
@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);
}
我觉得这不是做到这一点的最有效方法。但是,如果我将所有的bitmaptextureatlastextextureregionfactorys'''指向一个bitmaptextureatlas,而这些“图像”在同一坐标处,那么即使我只调用其中的1个,这些图像也会互相加载。
这个问题的一个例子是:
@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”自动在彼此上自动加载,即使我只调用其中的1个。
我这样做正确吗?还是有更有效的方法?
解决方案
您的纹理可以包含多个资源。将其视为精灵表。或喜欢将照片粘合到一张白色纸上。您不需要每个纹理区域的新纹理。例如:假设您有星形图像,即250x250像素和100x100像素的太空飞船图像。您可以将这两个都放在测量512x256的质地上。您可以在0、0创建恒星(250x250)的纹理区域(250x250)。然后在251,0为太空飞船创建第二个纹理区域。
在这种情况下,如果它们足够小,仍然有一些剩余的图像炸毁太空船。下图显示了如果您可以在内存中看到纹理的外观。
希望这可以帮助。
其他提示
您的纹理很大!您是否非常确定您需要这么大?
不隶属于 StackOverflow