Reputation: 348
I'm using LibGDX and I have a characterSheet that is on the for of an 2D array. Basically it has 4 row, the first row has 8 columns, the second row has 5 and next two rows repeat. I want to get all the elements in the first row using nested for loops and the repeat for each row. Here is what I have for the first row. Is there a better way of doing it?
Array<TextureRegion> frames = new Array <TextureRegion>();
// Walking animation
for( int row =0; row< 1; row ++)
{
for(int col=0 ; col<8; col++)
{
frames.add(new TextureRegion(getTexture(), 0,0,64,64));
}
walking = new Animation(0.25F, frames);
frames.clear();
}
Upvotes: 0
Views: 81
Reputation: 460
The best way of doing this IMHO is using a TextureAtlas:
Animation walk = new Animation(1/30f, atlas.findRegions("walk"), Animation.PlayMode.LOOP);
That way you wont need to calculate positions, TextureAtlas will do that for you.
Upvotes: 2