FlixelCommunity / flixel

Community fork of Adam “Atomic” Saltsman's popular game engine Flixel. Distilled from a variety of Flash games he worked on over the last couple years, including Gravity Hook, Fathom and Canabalt, its primary function is to provide some useful base classes that you can extend to make your own game objects.
http://flixelcommunity.org/
Other
84 stars 17 forks source link

Replace “accumulator >= step” by “accumulator > step” in FlxGame.as #32

Open FlixelCommunityBot opened 12 years ago

FlixelCommunityBot commented 12 years ago

Issue #200 by: ghost

https://github.com/krix/flixel/commit/7fbc822359dfdfd6d74d9b9eaf86e0699c1cb0da

More explanation: http://forums.flixel.org/index.php/topic,5072.0.html

FlixelCommunityBot commented 12 years ago

Comment by: avoxgames

There is a danger that at the first time a call of the function step() may be skipped (when you set high framerate, for example FlxG.flashFramerate = 90) and _state.draw() will fail.

IQAndreas commented 11 years ago

For anyone digging into this issue, I have found these two articles which should help:

IQAndreas commented 11 years ago

I have been trying to dig into this issue myself, and although I now understand the idea behind the deterministic delta-tee, I'm having some difficulty juggling those variables in my head, but I think I have a solution.

This is how the original code looks (with Krix's addition which seems to also be recommended by the article mentioned earlier):

_accumulator += elapsedMS;
if(_accumulator > _maxAccumulation)
    _accumulator = _maxAccumulation;
while(_accumulator >= _step)
{
    step();
    _accumulator -= _step;
}

And this is my idea, which would ensure that step() is always run at least once, whether the framereate is high or low, or is catching up after some lag.

_accumulator += elapsedMS;
if(_accumulator > _maxAccumulation)
    _accumulator = _maxAccumulation;
do
{
    step();
    _accumulator -= _step;
} while(_accumulator >= _step);  // <-- would this now be "greater than" or "greater than or equals"?

However, I'm very uncertain whether or not I'm thinking along the right lines, so I would like someone else to check me on this.