Synchronizing sprite movement

Started by
1 comment, last by d_aelion 22 years, 2 months ago
Okay, I know everyone out there already knows the answer to this and it may sound stupid, but I don''t know a good way to get a sprite to move. Let me explain: In comparing games like Diablo and Zelda (sprite Zelda, not the 3d ones), I noticed that the number of walking frames of animation are different, but that the animations are not too fast or two slow. For example, Zelda only has 2 animations for walking, left-foot forward, left-foot back, whereas Diablo has a lot more. The point is is that their is some code deciding when to change the frame during movement. I know the answer is simple but I have yet to figure it out. Any help would be appreciated.
Advertisement
To keep the speed consistant in a tile based game you basically lock the frame rate. There are two ways to do that. One uses a WHILE and one uses an IF. WHILE stops everything where IF stops everything that is using the timer but keeps everything else moving. Both are faked versions of time based movement but using IF allows for dropped frames as well which does come in handy for graphic intense areas of your game.

If you have 2 frames that you want to display over 8 frames you have a unsigned char frame counter in your character struct that''s incremented every frame. To see what frame you''re on you simply divide the current framecount by 4. You''ll get a 0 for four frames and 1 for four frames. If you want four frames, you divide by 2 and so on. If you want to allow for up to 16 frames instead of 8, just adjust the mod number accordingly.

render()
{
character.frame++;
character.frame%=8;
drawframe(character.frame/4);
}

If you want to have variable frame length animations just change the divide number to a variable based on the animation sequence.

Ben

[The Rabbit Hole | The Labyrinth | Programming | Gang Wars | The Wall]
When to change frame during movement.......
pretend you were watching someone walk, they walk at pretty much the same rate - if you want to get the timing realistic, time yourself how long it takes to walk a certain distance then divide it by the amount of steps you took

Its up to you how smooth you want the animation (20 frames is easily good enough) then you would just draw/blit another frame once every 1/20th of a second.
easy!
(apart from drawing the 100 frames )

This topic is closed to new replies.

Advertisement