Jump to content

Update function call rate


hellspawn_bg
 Share

Recommended Posts

A noob question over here. Is it safe to update the position of the character in the update function. My concern is that on faster devices the character would appear running faster than on slower ones. How can I make sure that on faster devices the update function will not be called more than 60 times per second and the game would look as smooth as on slower ones, running exactly on 60 frames? Is it something that is build in phaser, or do I have to implement some custom logic to work around this?

 

Thanks in advance!

Link to comment
Share on other sites

I don't know.

 

I see it as potentially useful to solve your problem, but I've never used it, and I've never planed to regulate the frame rate.

 

"How can I make sure that on faster devices the update function will not be called more than 60 times per second"

 

I think it just can't.

Unless you change the delta cap value, it's 60fps max no matter what.

 

Not sure about that though, rich could certainly enlighten us.

Link to comment
Share on other sites

Phaser will run at 60fps maximum using requestAnimationFrame - it should never run faster than this. It can however run slower than that, so if you have to ensure a consistent speed for something to happen at you have to factor in the elapsed 'delta time' (the time taken since the last frame) as a multiplier.

// Get the time in seconds since the last framevar deltaTime = game.time.elapsed / 1000;// Move the character to the right at 500 pixels per second, regardless of frameratecharacter.x += 500 * deltaTime;
Link to comment
Share on other sites

Almost, requestAnimationFrame runs as fast as the monitors frame/refresh rate which can be 120 fps for a 120Hz monitor. (of course most people don't have those)

But as said, the best would be to travel over time, using deltas, instead of frames.

 

http://www.blurbusters.com/wp-content/uploads/2013/08/InternetExplorerRequestAnimationFrameBenchmarks.png

Link to comment
Share on other sites

Almost, requestAnimationFrame runs as fast as the monitors frame/refresh rate which can be 120 fps for a 120Hz monitor. (of course most people don't have those)

But as said, the best would be to travel over time, using deltas, instead of frames.

 

http://www.blurbusters.com/wp-content/uploads/2013/08/InternetExplorerRequestAnimationFrameBenchmarks.png

50Hz is also an uncommon but possible refresh rate eg. where a PC is connected to a PAL "television" via HDMI

Link to comment
Share on other sites

I wasn't actually aware RAF ran above 60hz - it makes sense that it's synced to vertical refresh but for some reason I figured it was capped. I guess in the majority of cases (almost all modern flat-screen displays, mobile phones and so on) you can expect 60hz, but yeah, there are gaming panels, CRTs and newer mobile screens which support higher refresh rates. Interesting stuff Sebastian!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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