Sprite animation

Hi,

I used sprite sheets in my game to store all my sprites, each sprite was the same size, not I’ve got more sprites and they range in sizes, what is the best way to animate these? Can I use texture packer for this and get the size information from the atlas text file or possibly the texture once you got it or something?

Something like:


        TextureAtlas textureAtlas = new TextureAtlas(Gdx.files.internal("sprite.atlas"));
        texture = textureAtlas.findRegion("0001").getTexture();
        Gdx.app.log(TAG, "Texture width: " + texture.getWidth());
        Gdx.app.log(TAG, "Texture height: " + texture.getHeight());

I suspect the above though would give the size of the whole sprite sheet?

As the sprites will be different sizes, I would need this for the collision detection too.

Thanks for any advice.

Hi,

This seems to get the width and height:


	TextureAtlas textureAtlas = new TextureAtlas(Gdx.files.internal("badguys.txt"));
		img = textureAtlas.findRegion("Enemy12_Walk_0000_Layer-1").getTexture();
		AtlasRegion reg = textureAtlas.findRegion("grunt_1");
		System.out.println(reg.getRegionWidth() + "," + reg.getRegionHeight());
		batch = new SpriteBatch();

How should the regions be names to make it easy to do animations etc? I thought of something like:

Grunt_1
Grunt_2
Grunt_3

This would be for a grunt sprite which has 3 animations. My issue with this is, some of the sprites have more than 3 animations.

Quick update, using Sprite makes the code easier as don’t need to get width, height etc.

See here: http://pastebin.java-gaming.org/605950b8a4e1e

Of course I would use Animation class to do the animation and not that timer in the code!

use spine ^^ its awesome ^^