Flixel Forums

development => releases => Topic started by: krix on Wed, Sep 7, 2011

Title: How to smooth framerate in Flixel 2.5
Post by: krix on Wed, Sep 7, 2011
Have you ever noticed these weird framedrops in Flixel 2.5 which result in choppy movement of your sprites?
Even if your game runs constantly at 60fps!?

Well I think I have a fix for you! :)

Since Flixel 2.5 frames will be skipped if a given framerate can not be hold.
This is basically a good thing, because otherwise your whole game would be slowed down in this case!
Unfortunately there is a bug in the routine that decides to skip a frame or not, which can cause unnecessary frameskips.

To fix this find the function onEnterFrame in FlxGame.as and change the line:
Code: [Select]
while(_accumulator >= _step)to:
Code: [Select]
while(_accumulator > _step)
Also see my github change here:
https://github.com/krix/flixel/commit/7fbc822359dfdfd6d74d9b9eaf86e0699c1cb0da (https://github.com/krix/flixel/commit/7fbc822359dfdfd6d74d9b9eaf86e0699c1cb0da)

Thanks to this small change my sprite movements are smooth as ice cream! :)

Sidenote:
Set Flash Framerate and Game Framerate to 60 to achieve maximum smoothness.
You can to this by setting the properties directly:
Code: [Select]
FlxG.framerate = 60;
FlxG.flashFramerate = 60;
or you can set them directly in the constructor of your FlxGame object:
Code: [Select]
super(320, 240, GameState, 2, 60, 60);

Please let me know if this also works for you.

Cheers,
Dirk

[EDIT: Also have a look on this additional improvement: http://forums.flixel.org/index.php/topic,4543.0.html (http://forums.flixel.org/index.php/topic,4543.0.html)]
Title: Re: How to smooth framerate in Flixel 2.5
Post by: osro on Wed, Sep 7, 2011
Please let me know if this also works for you.

Confirmed! Nice catch :P

I was just wondering this problem too, is it my code or in Flixel :)
Title: Re: How to smooth framerate in Flixel 2.5
Post by: photonstorm on Wed, Sep 7, 2011
Nice tweak! I do something similar (which I outlined in my Flixel Display List blog post) that basically removes the accumulator from the equation, so it always does 1 step and 1 render per enter frame.
Title: Re: How to smooth framerate in Flixel 2.5
Post by: rgilbert on Thu, Sep 8, 2011
Nice. Doesn't seem to help for mobile though, but I see improvement on desktop.
Title: Re: How to smooth framerate in Flixel 2.5
Post by: goatfishstudios on Sun, Oct 9, 2011
Thanks krix for this tweak, it improved the flow of the game and smoothness :D
I too thought It was my code or computer lol
Thanks again
Title: Re: How to smooth framerate in Flixel 2.5
Post by: test84 on Sun, Oct 9, 2011
and I always though it's my crappy Intel HD graphic card, tnx man.
Title: Re: How to smooth framerate in Flixel 2.5
Post by: Gama11 on Fri, Oct 28, 2011
I've been wondering about the "lag" that kept appearing in my latest project - appearently this fixed it. :D Thx a lot!
Title: Re: How to smooth framerate in Flixel 2.5
Post by: camasthecat on Fri, Oct 28, 2011
Hey, it works! Thanks a lot!
Title: Re: How to smooth framerate in Flixel 2.5
Post by: test84 on Fri, Oct 28, 2011
I don't know why but even when I see a 60fps, it doesn't feel like one, comparing to other platformers.
Title: Re: How to smooth framerate in Flixel 2.5
Post by: datorum on Fri, Oct 28, 2011
thx! Awesome! You just saved my day.
you should also rename the topic and add "how to improve overall performance", my game also runs faster - a smoothed framerate is a result of that, but at first I thought this was mostly for games that run at 30/30 fps and not those which run with 15/30 fps like mine.

Title: Re: How to smooth framerate in Flixel 2.5
Post by: fAlone on Sat, Mar 2, 2013
Sorry for bringing this back from the dead, but I need to know something.

This is already fixed in the latest Master, right?  So we don't need to make any changes if that's what we downloaded?
Title: Re: How to smooth framerate in Flixel 2.5
Post by: Wing Eraser on Sat, Mar 2, 2013
Looking at the master branch, it isn't applied: https://github.com/AdamAtomic/flixel/blob/master/org/flixel/FlxGame.as#L451

Neither for the community version: https://github.com/FlixelCommunity/flixel/blob/dev/org/flixel/FlxGame.as#L451
Title: Re: How to smooth framerate in Flixel 2.5
Post by: Dovyski on Sun, Mar 3, 2013
Neither for the community version: https://github.com/FlixelCommunity/flixel/blob/dev/org/flixel/FlxGame.as#L451

There is an open issue (https://github.com/FlixelCommunity/flixel/issues/32) regarding that bug. Since it is easy to fix, I think it will be applied to master soon.
Title: Re: How to smooth framerate in Flixel 2.5
Post by: Kramer on Sun, Jun 2, 2013
I have some levels that are currently getting around 47fps, and others that get 60.

I believe this change is great if you can get your levels all working at the same FPS, but in my case applying this fix will cause the slower FPS levels to also play slower. Not using this fix keeps levels that have a lower frame rate to still play at the same pace as the higher frame rate levels... But it sure is a heck of a lot smoother using this fix, so I'm going to try my best to squeeze out 60fps on all my levels, that way I can for sure use this fix :p