2D animation

Started by
3 comments, last by Sirisian 17 years, 5 months ago
Currently im making a 2d rpg , and at the moment im adding the statistics of some items(in txt file(s))...everything's fine here.. The next step will be the most important(in my opinion) , which is .. the animation of every object in the world. How can i create a simple animation system ? What's the best way ? im using bitmap files(SDL libs) for every object if that matter;s...
Advertisement
I use DirectX, but my technique was derived from an SDL tutorial so it should work. You have 2 classes: Sprite and SpriteBase. SpriteBase is loaded from a text file, and one of these is created for each different Sprite Image. ie. You will have a text file for each Image file you want to load, and in the text file you will give the image name, and animation data. for each animation, i put a number of frames and each frame contains a Rectangle to use as a source from the image. The sprite class contains a reference to a spritebase. The sprite class contains sprite independant data ie. current animation etc. This way you can create 1000 sprites based on a single spritebase. Each update of the sprites will call currentanimation.update(); that will decide if the next frame is to be set depending on speed (set in the text file of a spritebase). I found this technique extremely effective in my C# Managed DirectX games.

good luck.
Heh, just posted a post on using spritesheets here.

What I do in my game is giving each sprite a list of animations, and each animation a list of frame indices, and let the image sort out which region to draw based on this frame index. Of course, it needs to know not only the image size, but also the frame size to work correctly (I prefer to keep frames the same size, rather than setting a rectangle for each frame, because it's easier to use). You may also want to add animation speed control.
Create-ivity - a game development blog Mouseover for more information.
cool thanks for the information...i think i got it..

*Create a class with all the images
*Depends the action switch the current_animation int index
*update the main surface with the new image

But , how can i make it automatically? i mean if i just make a counter , you think that it will work?

*with counter , i mean something like this:
counter=0
while (game)
if counter <=100 counter+=1
if (counter>=100)
{
if current_anim <=max_index
{
change anime(in case we have a list .. just increase the index)
counter=0
} else {
current_anim=0
counter=0
}
}
might wanna make it time based. Using FPS to control animation is very odd, especially if your game can't run at a constant FPS on all computers.

This topic is closed to new replies.

Advertisement