Jump to content

Clamp framerate


qdrj
 Share

Recommended Posts

I'm developing game with scrolling background and stuff. 

 

Framerate is changing between 50-60fps. Such fps will be good for any other game. But in my game it looks jerky and unpleasant.

 

So I would like to set for example 45fps instead.

 

Is there any way to do this in Phaser?

 

Thanks in advance!

Link to comment
Share on other sites

Not without some hacking; Phaser uses requestAnimationFrame which is handled by the browser to be called at 60fps, the same as the refresh rate on almost all devices. You could probably force Phaser to use setTimeout instead and then modify the timeout length so you get your desired fps (the timeout is in ms so you'll need to do 1000/fps to get the value you need; 45fps is roughly 22.22, though I'd probably recommend 30fps - 33.33 - to prevent jitter) but I can't guarantee things such as physics will work correctly.

Link to comment
Share on other sites

Not without some hacking; Phaser uses requestAnimationFrame which is handled by the browser to be called at 60fps, the same as the refresh rate on almost all devices. You could probably force Phaser to use setTimeout instead and then modify the timeout length so you get your desired fps (the timeout is in ms so you'll need to do 1000/fps to get the value you need; 45fps is roughly 22.22, though I'd probably recommend 30fps - 33.33 - to prevent jitter) but I can't guarantee things such as physics will work correctly.

Thank you! I will try setTimeout.

 

Can you explain please why to use exactly 30fps to prevent jitter?

Link to comment
Share on other sites

Because if your screen refresh rate is 60hz, then 30fps will mean every frame will last exactly 2 refreshes. If you use 45fps, then frames will start to land in-between refreshes, meaning you double up and miss frames due to the two being out of phase. This is one of the reasons why requestAnimationFrame is so smooth; everything happens exactly once per refresh.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...