0
votes

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

1 Answers

0
votes

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.