PDA

View Full Version : Frames Per Second



smiley
07-27-2002, 01:33 PM
When i have v-sync enabled i get 60fps in my game and it runs smoothe. However if i disable v-sync i get about 4000 fps and the game is too fast.

How can i make the game run at the same speed no matter what v-sync is?

-Carl

Bob
07-28-2002, 06:05 AM
Make your movements based on the time of the last frame, instead of constant per frame.

First, you need to modify your code, so all movement numbers are based on units per second instead if some constant value.

Second, measure the time taken to render last frame, and use that time and multiply it by the new movement value.

Example: A ball is moving at a speed of 100 units per second. Last frame took 4ms to render (that's 250 fps). The distance to move it this frame should be 100 * 4ms = 0.4 units. If your frame time goes up to 10ms for a while, new movement would be 100 * 10ms = 1.0 units.

This will keep your program running at the same speen independent of framerate. For a high framerate, this requires a timer with rather high resolution. I suggest you turn on the v-sync to prevent pushing the timer to the limit of it's resolution.