0

I am following libgdx tutuorial on texture atlases. This is an excerpt from a texture atlas file. What is the meaning of index parameter and in what situations it is useful to the programmer? All texture region have it and it is the same namely -1, in all of them.

prehistoric.png
format: RGBA8888
filter: Nearest,Nearest
repeat: none
background
  rotate: false
  xy: 2, 2
  size: 1280, 720
  orig: 1280, 720
  offset: 0, 0
  index: -1
trex
  rotate: false
  xy: 1286, 479
  size: 179, 243
  orig: 179, 243
  offset: 0, 0
  index: -1
caveman
  rotate: false
  xy: 1286, 319
  size: 83, 156
  orig: 83, 156
  offset: 0, 0
  index: -1
potato
  • 4,479
  • 7
  • 42
  • 99

2 Answers2

3

From the Javadoc:

The number at the end of the original image file name, or -1 if none.

When sprites are packed, if the original file name ends with a number, it is stored >as the index and is not considered as part of the sprite's name.

I should also add, that this index is also used on findRegion(String name, int index) method which returns the first region found with the specified name and index.

Community
  • 1
  • 1
nrallakis
  • 161
  • 11
1

It's typically used for animations. You can append frame numbers to the file names of each frame of animation before you pack them into the atlas, i.e. run0.png, run1.png, run2.png, etc. During texture packing, the number is removed from the sprite's name and used as its index. Then you can load the animation all at once:

animation = new Animation(0.1f, atlas.findRegions("run"));

The index is -1 when the original file name did not end in a number.

Tenfour04
  • 83,111
  • 11
  • 94
  • 154