Texture packing animation images/Sprite sheets efficiently-Libgdx

僤鯓⒐⒋嵵緔 提交于 2019-12-12 04:32:13

问题


For my LibGdx project,I have assets including single images and sprite sheets for animation.I know it is efficient to pack everything in to a single atlas.

But when it comes to sprite sheets,how can I pack it?Do I have to use a single sprite sheet or single images of a sprite sheet while packing? Eg:I have a sprite sheet named 'snake' with 4 frames. also I have snake frames in snake_01,snake_02,snake_03 and snake_04.

Which one is the better way?


回答1:


The second way is much less time consuming to manage. So use separate files for each frame of animation, like snake_01.png, snake_02.png, etc.

LibGDX TexturePacker will automatically name all these regions "snake" and give them an index number.

Then, after loading the TextureAtlas, you can pull whole animations out:

Array<TextureAtlas.AtlasRegion> snakeRegions = textureAtlas.findRegions("snake");
Animation<TextureRegion> snakeAnimation = new Animation<TextureRegion>(0.1f, snakeRegions);

If you are using a version of LibGDX older than 1.9.5, omit the <TextureRegion> (two times). The Animation class became generic in version 1.9.5.



来源:https://stackoverflow.com/questions/41759700/texture-packing-animation-images-sprite-sheets-efficiently-libgdx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!