Frame rate Independent?
by Chris Cockcroft · in Torque Game Builder · 02/09/2006 (6:24 pm) · 3 replies
Hey,
I'm playing around with the new beta (1.1) on my iBook G4, and am getting some weird issues with varying frame rates and the physics system.
It used to be when I ran a high resolution, my frame rate would drop and the game would be a little choppy. However, the sprites would move at the same rate as they would with a higher frame rate. Now, everything in my game slows down when the framerate drops, and speeds up when the framerate rises (sometimes to an uncontrollable level).
Is the physics system no longer frame rate independent? Or am I missing a setting?
Thanks for any help :)
Chris
I'm playing around with the new beta (1.1) on my iBook G4, and am getting some weird issues with varying frame rates and the physics system.
It used to be when I ran a high resolution, my frame rate would drop and the game would be a little choppy. However, the sprites would move at the same rate as they would with a higher frame rate. Now, everything in my game slows down when the framerate drops, and speeds up when the framerate rises (sometimes to an uncontrollable level).
Is the physics system no longer frame rate independent? Or am I missing a setting?
Thanks for any help :)
Chris
About the author
#2
Good Luck,
- Melv.
02/11/2006 (7:52 am)
Well, I certainly wouldn't be doing lots of impulses every second as it begs the question why not just do less with slightly bigger impulses but if this isn't the case here, I guess a way to achieve this would be to use the periodic timer available on every "t2dSceneObject" e.g. "setTimerOn()" and "setTimerOff()".Good Luck,
- Melv.
#3
but if you do, there's a couple options -
you can do the math to account for the framerate, eg
or you could write what you suggested, a way to call a function a specific number of times per second, independent of framerate.
i wrote one of these once, i think i called it a framerate normalizer.
usint it looked like this:
i forget the implementation of howManyTicks() ;)
but i don't think it was very tricky.
02/11/2006 (9:19 am)
I think the right thing to do is not to update physics in framerate-based code,but if you do, there's a couple options -
you can do the math to account for the framerate, eg
// secondsPerFrame = 1.0 / framerate; impulse = impulsePerSecond * secondsPerFrame;- this can get tricky if your math is heavily non-linear.
or you could write what you suggested, a way to call a function a specific number of times per second, independent of framerate.
i wrote one of these once, i think i called it a framerate normalizer.
usint it looked like this:
...
myFramerateNormalizer.desiredTicksPerSecond = 30;
...
someFrameRateDependentFunction()
{
numTicksNeededThisFrame = myFramerateNormalizer.howManyTicks();
for (i = 0; i < numTicksNeededThisFrame; i++) {
foo.tick();
}
}i forget the implementation of howManyTicks() ;)
but i don't think it was very tricky.
Torque Owner Chris Cockcroft
Is there a way to call aan update function a specific number of times per second that would be independent of the frame rate? Are schedules the only way?
Thanks again :P
Chris