Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

d_aelion

Synchronizing sprite movement

This topic is 6012 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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 )

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!