AndEngine - 在一个场景中所有textureRegion 1 textureAtlas;可能? [英] AndEngine - one textureAtlas for all textureRegion in a scene; possible?

查看:167
本文介绍了AndEngine - 在一个场景中所有textureRegion 1 textureAtlas;可能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到,我可以保留一个图谱一textureRegion虽然我可以同一区域多次绘制一个精灵。是否有可能保持在一个textureAtlas所有textureRegions在一个场景?

I noticed that I can keep one atlas for one textureRegion although I can draw same region multiple times as a sprite. Is it possible to keep all textureRegions in one textureAtlas in a scene?

我的特殊情况是,我生成图像,而不是使用任何图像文件。我这样做与BaseBitmapTextureAtlasSourceDecorator和生成IBitmapTextureAtlasSource的区域。

My special case is, I am generating images instead of using any image file. I do this with BaseBitmapTextureAtlasSourceDecorator and generate the region from IBitmapTextureAtlasSource.

推荐答案

是的。一般情况下,虽然,你应该只创建一个1024一个最大宽度/高度地图集(这些大小必须是2的幂,顺便说一句),是有效的。

Yes. Generally, though, you should only create atlases with a a max width/height of 1024 (these sizes must be powers of 2, by the way), to be efficient.

在另一方面,我发现它更容易使用BuildableBitmapTextureAtlas。有了这样的图谱,你不必指定阿特拉斯你把你的纹理。我想这也可能采取的精灵出血到一定程度(不知道,虽然)。这其实是同样的想法...这里是从我的项目的例子:

On another note, I've found it easier to use BuildableBitmapTextureAtlas. With this kind of atlas, you don't have to specify where in the atlas you are placing your textures. I think it also might take care of sprite-bleeding to some degree (not sure, though). It's the same idea really... Here is an example from my project:

BuildableBitmapTextureAtlas buttonAtlas = new BuildableBitmapTextureAtlas(getTextureManager(), 512, 512, TextureOptions.BILINEAR_PREMULTIPLYALPHA); 
model.moveLeftButtonTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(buttonAtlas, this, "moveleft_button.png");
model.moveRightButtonTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(buttonAtlas, this, "moveright_button.png");
model.handleBlockButtonTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(buttonAtlas, this, "handleblock_button.png");
model.restartButtonTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(buttonAtlas, this, "restart_button.png");

try{ buttonAtlas.build(new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(0, 1, 1)); }
catch(Exception e){ e.printStackTrace(); }
buttonAtlas.load();

在您的情况下,使用下面的方法:

In your case, use the following method:

BitmapTextureAtlasTextureRegionFactory.createFromSource(BuildableBitmapTextureAtlas atlas, IBitmapTextureAtlasSource source)

在总结,阿特拉斯只拥有所有你添加到它的纹理。然后,你这本地图集加载到内存中,因此这些纹理,可快速检索。然后,您可以使用一个纹理的单个实例,你希望建立尽可能多的独立的精灵。

In summary, the atlas just holds all the textures you add to it. Then you load this atlas into memory so that these textures can be retrieved quickly. You can then use a single instance of a texture to build as many independent sprites as you wish.

这篇关于AndEngine - 在一个场景中所有textureRegion 1 textureAtlas;可能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆