TiledSprite没有按预期工作
问题描述:
我似乎无法像我期望的那样让TiledSprite工作。没有手册,AndEngineExamples中的示例没有任何帮助。TiledSprite没有按预期工作
考虑以下代码:
@Override
public void onLoadResources() {
BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
mBlockAtlas = new BitmapTextureAtlas(512, 512, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
mBlockTexture = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(mBlockAtlas, getApplicationContext(), "num_plasma.png", 0, 0, 3, 3);
getTextureManager().loadTexture(mBlockAtlas);
}
这加载一个512x512的质感,我已经 - 人工 - 分为3x3的瓷砖只是为了测试目的。现在,这样做:
public Scene onLoadScene() {
mScene = new Scene();
mScene.setBackground(new ColorBackground(0.5f, 0.1f, 0.6f));
TiledSprite foo, foo2;
foo = new TiledSprite(0, 0, mBlockTexture);
foo.setCurrentTileIndex(1);
foo2 = new TiledSprite(0, 200, mBlockTexture);
foo2.setCurrentTileIndex(5);
mScene.attachChild(foo);
mScene.attachChild(foo2);
return mScene;
}
这使得两个精灵在屏幕上(如预期),但他们都显示相同的瓷砖(5)!
如果你有一堆使用相同纹理但显示不同瓷砖的精灵,应该怎么做?
答
我认为你需要deepcopy的()的时候,你所创建的精灵的纹理,像
foo2 = new TiledSprite(0, 200, mBlockTexture.deepCopy());
谢谢,这帮助它。对我的60+精灵使用deepCopy()会确保很多内存,所以我在考虑使用TextureRegionFactory.extractFromTexture(),但是该方法需要一个Texture,而我的纹理是一个TextureRegion。你有任何线索如何使这项工作? – bos 2012-03-15 12:06:31
我没有使用TextureRegionFactory,但TextureRegion扩展了BaseTextureRegion,它具有getTexture()的getter() – jmroyalty 2012-03-15 12:27:26
您确实是一个节省时间的工具。谢谢! – bos 2012-03-15 12:34:19