Author Topic: How to smooth framerate in Flixel 2.5  (Read 10464 times)

krix

  • Member
  • **
  • Posts: 61
  • Karma: +0/-0
    • View Profile
How to smooth framerate in Flixel 2.5
« 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

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]
« Last Edit: Wed, Sep 7, 2011 by krix »

osro

  • Active Member
  • ***
  • Posts: 121
  • Karma: +1/-0
    • View Profile
    • Purppura
Re: How to smooth framerate in Flixel 2.5
« Reply #1 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 :)
« Last Edit: Wed, Sep 7, 2011 by osro »

photonstorm

  • Administrator
  • Key Contributor
  • *****
  • Posts: 1502
  • Karma: +1/-0
    • View Profile
    • Photon Storm
Re: How to smooth framerate in Flixel 2.5
« Reply #2 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.
http://www.photonstorm.com



"Tell me and I will forget, show me and I might remember, involve me and I will understand" - Confucius

rgilbert

  • Member
  • **
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: How to smooth framerate in Flixel 2.5
« Reply #3 on: Thu, Sep 8, 2011 »
Nice. Doesn't seem to help for mobile though, but I see improvement on desktop.

goatfishstudios

  • Member
  • **
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: How to smooth framerate in Flixel 2.5
« Reply #4 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

test84

  • Key Contributor
  • *****
  • Posts: 1328
  • Karma: +0/-0
  • ت
    • View Profile
    • My personal site.
Re: How to smooth framerate in Flixel 2.5
« Reply #5 on: Sun, Oct 9, 2011 »
and I always though it's my crappy Intel HD graphic card, tnx man.
blog, twitter, Check out my award winning game, Rot Gut:

Gama11

  • Contributor
  • ****
  • Posts: 390
  • Karma: +0/-0
    • View Profile
Re: How to smooth framerate in Flixel 2.5
« Reply #6 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!

camasthecat

  • Contributor
  • ****
  • Posts: 461
  • Karma: +0/-0
  • WOW! 400+ Posts!? Jeez! Do I have a life!?!?
    • View Profile
    • My site for thermalJS, an HTML5/Javascript engine kinda-like flixel:
Re: How to smooth framerate in Flixel 2.5
« Reply #7 on: Fri, Oct 28, 2011 »
Hey, it works! Thanks a lot!

test84

  • Key Contributor
  • *****
  • Posts: 1328
  • Karma: +0/-0
  • ت
    • View Profile
    • My personal site.
Re: How to smooth framerate in Flixel 2.5
« Reply #8 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.
blog, twitter, Check out my award winning game, Rot Gut:

datorum

  • Active Member
  • ***
  • Posts: 165
  • Karma: +0/-0
    • View Profile
Re: How to smooth framerate in Flixel 2.5
« Reply #9 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.


fAlone

  • New Member
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: How to smooth framerate in Flixel 2.5
« Reply #10 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?

Wing Eraser

  • Contributor
  • ****
  • Posts: 477
  • Karma: +0/-0
  • ★★★★★
    • View Profile
    • Wing Eraser

Dovyski

  • Member
  • **
  • Posts: 31
  • Karma: +0/-0
    • View Profile
    • As3GameGears
Re: How to smooth framerate in Flixel 2.5
« Reply #12 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 regarding that bug. Since it is easy to fix, I think it will be applied to master soon.

Kramer

  • Member
  • **
  • Posts: 74
  • Karma: +0/-0
    • View Profile
Re: How to smooth framerate in Flixel 2.5
« Reply #13 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
« Last Edit: Sun, Jun 2, 2013 by Kramer »