albin Posted April 22, 2014 Share Posted April 22, 2014 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 More sharing options...
d13 Posted April 23, 2014 Share Posted April 23, 2014 There's a lively and interesting discussion about game loop deltas going on here: http://forum.lostdecadegames.com/topic/196/what-is-the-best-practice-for-javascript-game-loop Link to comment Share on other sites More sharing options...
albin Posted April 23, 2014 Author Share Posted April 23, 2014 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! drhayes 1 Link to comment Share on other sites More sharing options...
fillmoreb Posted February 11, 2016 Share Posted February 11, 2016 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 More sharing options...
chg Posted February 12, 2016 Share Posted February 12, 2016 @fillmoreb I recall what the OP describes being a bug in Phaser which has probably been fixed since (it's a 2 year old thread you've resurrected) Link to comment Share on other sites More sharing options...
fillmoreb Posted February 12, 2016 Share Posted February 12, 2016 Weird... not sure how I managed. I never look past the first page or two of the forums. Color me embarrassed. Link to comment Share on other sites More sharing options...
Recommended Posts