0

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?

Niranjana
  • 514
  • 5
  • 23

1 Answers1

0

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.

Tenfour04
  • 83,111
  • 11
  • 94
  • 154
  • Thank you!One more thing,when I get region of a particular image,using findRegion(),I could see the portions of near by images in the atlas after rendering.How it is happening? – Niranjana Jan 23 '17 at 06:54
  • 1
    If sprites are drawn smaller than 1x1 the size in screen to original size, and you aren't using nearest filtering, linear filtering will cause nearby pixels on the atlas to bleed into the Sprite. Increase the padding in the texture packer settings to combat this. – Tenfour04 Jan 23 '17 at 11:54