Jump to content

Fixed timestep


albin
 Share

Recommended Posts

Hey!

 

Phaser really jives with me and I'd love to use it, but I have a couple of questions regarding the game loop. I've looked at the code and as far as I can tell Phaser's physics run on a fixed timestep but the state update function is run variably. I've looked through the examples and none of them deal with this.

 

For example, in this example the logo moves twice as fast on my desktop compared to my laptop because I'm on a 120hz monitor and requestAnimationFrame runs at 120 fps.

 

So, I'm looking for either resources explaining the Phaser game loop and how to handle update and maybe putting my fears about variable delta to rest, if there's a way to cram a fixed timestep into the state update function (maybe using game.enableStep?), or some tips for when I rewrite the core of Phaser to suit my needs.

 

Here's a friendly article on the subject: http://gafferongames.com/game-physics/fix-your-timestep/

 

Thanks!

Link to comment
Share on other sites

Thanks, but I'm already well versed on the subject.

 

When starting out I decided to build a game from scratch and iterated through multiple game loops for my own engine before settling on fixed timestep. I'm assuming though, since Phaser has been used for so much, that someone has thought things through thouroughly and that I'm possibly in the wrong for wanting it to be different. I just want to partake in that thought process so I know the correct way of thinking about it.

 

Here are a couple more resources that goes through everything: http://www.koonsolo.com/news/dewitters-gameloop/ and http://gameprogrammingpatterns.com/game-loop.html

 

The documentation is not explaining how to handle the game loop and I'm wondering why I'm seemingly the only one having trouble with it!

Link to comment
Share on other sites

  • 1 year later...

I haven't looked too deep into it, but as far as I know the update function is not running on a fixed timestep.  Even if the physics engine does use a fixed time-step, this code is bypassing it by setting the position directly, rather than setting a velocity and letting the engine move the body.  Try setting the velocity of the logo on that example instead of updating the position manually.  My guess is that at that point, it will run at the same speed on your two different machines.

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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