Jump to content
  • Advertisement
Sign in to follow this  
all_names_taken

How do I synchronize framrate?

This topic is 4584 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

How should I best handle framerate stuff? 1. Is it normal procedure to write all code so that it's easy to configure the framerate and all movement distances etc. by changing a constant. I.e. if I for example am to model a player running, he'll get 5 meters per second no matter which the framerate is, so that each frame he's moving he should move 5/frames_per_second meters. Is it the standard procedure to write all code in that way? 2. What's the best code for achieving frame synchronization so that each frame takes the same amount of time? Using windows timers or Sleep() seems to cause local and cumulative drift and makes the game very dependent on CPU speed. On the other hand, I can't remember where to find any info on how to ask system clock for time in milliseconds or other useful methods. And I heard somewhere that using the system clock wasn't always a good idea, anyone knows why it wouldn't be?

Share this post


Link to post
Share on other sites
Advertisement
I haven't got much info with me at the moment (no code to refer to) but I can offer a little advice maybe...

1. Yes. I learnt the hard way that it is a good idea to do this. I wrote a simple 2d platform game a few years ago on a Pentium 2 machine, and it all ran fine on there. But when I ran it on my P4 it was so fast it was unplayable! All because I had simply said things like "push right = move the player 4 pixels" rather than basing it on actual elapsed time. Without basing it on time, I don't really see a way of keeping everything running at 'normal' speed on different machines.

2. The best way I'm not sure of. But you could try keeping a delta value of the amount of time passed since the last frame was rendered. Depending upon the value of this delta you can move sprites/models/animations accordingly, or only render a new frame after a certain period of time etc.... You just need to get the time in milliseconds (can't remember the function offhand, something like timeGetTime() from the Windows SDK)

Hope this rambling helps a bit...

Share this post


Link to post
Share on other sites
Give your object a velocity of X pixels/second and multiply this by the number of seconds elapsed (which will be a very small number) in the frame. That's the number of pixels to move in that frame.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!