My approach is to ensure no matter the drawing frame rate fix the update frame rate to 60fps. The code I use to do this is this
private function onEnterFrame(e:EnterFrameEvent):void {
fTimeLeft += e.passedTime;
while (fTimeLeft > 0) {
gIMgr.Tick(1 / 60);
if (_fast) {
gIMgr.Tick(1 / 60);
}
fTimeLeft -= fTimeStep;
}
gDMgr.Tick();
e.stopImmediatePropagation();
}
The app is supposed to run at 60fps. But if for any reason it does not I use the time provided by the enter frame event to call my main loop (gIMgr.Tick
) enough times so that 60 of them happen a second. The other tick, gDMgr.Tick
, handles updating the graphics based on whatever just happened. There’s no point calling that more than once, if the frame rate has dropped under 60fps.
Forgot to mention in case it’s not obvious: _fast indicates turbo/2x play is active.