Search code examples
javaanimationtile

Tile game walking animation


I want to implement a walking animation into my game that I am making, however im not sure what the recommended way is.

You can see my game progress here the Pokémon graphics are just while testing, so don't worry about that.

As you can see I just have a pink square right now, but in the debug information you can see my "facing" direction.

Basically, I would like to have an animation for walking in each direction. If possible I also want to add an "idle" animation so your character does sometime discreet when stood still for a while(maybe move its head).

What method should I be using?

Multipul pictures? Sprite sheets? or something else?

Any information would we appreciated.

Thanks

EDIT:

I am working on a SpriteSheet reader, I have it working fine however I can figure our how I can draw the background of the colour tranparent.

For example, I am using this spritesheet SpriteSheet, you can see it has a white background, when drawing this on my game I can see the white Example. Is this possible to remove?

If it helps this is how I draw the player

 g.drawImage(GameHelper.localPlayer.getImage(), ((16 * HelpersPackage.GeneralHelper.TileScale)* HelpersPackage.GameHelper.localPlayer.Location.X), ((16 * HelpersPackage.GeneralHelper.TileScale)* HelpersPackage.GameHelper.localPlayer.Location.Y), (16 * HelpersPackage.GeneralHelper.TileScale), (16 * HelpersPackage.GeneralHelper.TileScale), null);

EDIT 2:

Never mind, I have made my image transparent and it works well :)
Thanks


Solution

  • gamedev.stackexchange.com may be able to help you more.

    Sprite sheets are probably the best way to go if you're doing it from scratch. Each frame of the animation has a different x and y offset within the larger sprite sheet file. You keep track of which frame of which animation you're currently on, and draw the appropriate piece of the sprite sheet each frame. Deciding which animation to use and when to play an idle animation will have to be handled by the same parts of your code that handle user inputs, collisions, etc.

    Alternatively, you may be able to find existing libraries or game engines with sprite animation classes. Sometimes, these can save you a lot of coding time. Unfortunately, I'm not familiar with any specific good, free ones for java.