Animation Timing in Tile Games

Started by
4 comments, last by nino 22 years, 8 months ago
Ok I am making a tile based RPG (isn''t everyone?) and i was wondering what people do to control animation timing in these type of games. What i mean is say i want to have an animation that is 8 frames long, how do i know how often to change the frame to make this animation run smoothly? i could make the entire animation run once every second but what about animations that are 16 frames long or more? they would go too fast so what i want to know is, is there any way to take an animation and calculate how fast to display it depending on how many frames there are? I hope someone can understand this Thanks in advance NiNo
Advertisement
One simple way of approaching it... Store 2 numbers with everything that gets animated: the ''num_frames'' and the ''current_frame''. Each time you draw the animation, you increment the ''current_frame''. When current_frame equals num_frames, you reset current_frame to zero. Then you just draw the frame with the index of ''current_frame''.
thanks Kylotan but thats not what i mean

its kind of hard to explain but what i want to know is how do i figure out how much of a delay there should be between frames?

is there a way to figure it out algoritmically or do you have to play around with every animation to figure out how often to change its frames to make it look right?

i hope that clarifies things


Thanks,

NiNo
The best way to do it is to store with each frame a millisecond length of that frame, or with each series of frames a frame rate for that animation.

Within the character you store the current frame number and a lastswitched variable.

When you draw the character you check the current time, usuable stored in a global, and if the current time is greater than lastswitched time plus the current frame''s length you update to the next frame and reset the last switched time. You can even drop frames if you''re drawing the screen slower than the number of frames you have to maintain a constant rate.

As to how long to hold frames for there is no good algorithmic way to figure it out you have to tweek each frame on an individual basis or create animations that have a constant framerate. A good start is that film runs at 24 frames per second so each fram is held for approximately 40 milliseconds. A lot of animation is done at half that, or 12 fps or hods of about 80 milliseconds. So you figure out how long you want an animation to take, then you can calculate how many frames you''ll need.

hope this helps,









mat williams
Lead Programmer, Designer
Zero Sum Software
www.zero-sum.com
mat williamsLead Programmer, DesignerZero Sum Softwarewww.zero-sum.com
Well, my Idea would be the following:

1) There are 25 Frames per second (Or 10, or 100, or 25, or 1 Billion, whatever)

2) You know how many frames there are for each sprite.

So, now you take the total ammount of frames per sec. and divide them by the Amount of frames for that sprite. You can do this before your game stars, so it doesn''t go into the draw routine and slows it down (A simple var. INT will do). Now you check so that only every X frame the animation is updated one. That will update a 25 animation frame sprite 25 times a second (var INT == 1) and a 5 animation frame sprite 5 times a second (var INT == 25/5 == 5). Of course, if your sprites have different speeds, they would need an Add_X and Add_Y to define how far they move each frame or second.

I hope you understood what I was wanting to tell you. My english is not that good and to tell the truth I''m pretty drunk.
May you live in interesting times...
Well, there''s not really an ''algorithm'' for what you describe because it''s too basic. Frames and frame rates are decided by you. If you want 8 frames per second, you have 1 second / 8 frames = 1000ms / 8 frames = 125 ms per frame. If you want 33 frames in a second for a certain sprite then that''s 1000ms/33 = 30ms per frame. You get to decide how many frames you want, you get to decide how often you want them to run. If you want certain frames to last longer than others, you will just have to manually decide on the number of milliseconds for each frame. You just keep track of when you change a frame and compare it each time... if the number of ms elapsed is enough so that another frame is due, you change the frame. You can also subtract the difference between elapsed time and frame time from the next frame to keep it running reasonably smooth, but you might end up skipping frames this way. It''s up to you.

This topic is closed to new replies.

Advertisement