Jump to content

main game loop (update) - separate logic and render


mgrcar
 Share

Recommended Posts

Hi All,

 

This is my first post, my first user of a forum, my first use of Phaser, my first game that I'm thinking of making, my first everything... So please bear with me if I'm doing sth unusual here :)

 

I am looking at Phaser for a pixel-art game. One thing that I cannot get through my skull is how the update() should work. Therefore I made some assumptions for which I'd like to know if they're OK.

 

update() is called imediately after a repaint. Then you have around 1000 / 60 ms to do your stuff (logic + rendering). And if you're fast enough, whatever you did there (moved sprites around etc.) will show at the next refresh (repaint). I also assume that update() is called via requestAnimationFrame under the hood. So the construct under the hood is something like this:

update()

{

requestAnimationFrame(update);

// logic

// rendering

}

 

If this is all true, then what happens if the frame rate drops? Your "logic FPS" drops as well and the game slows down? Am I suppose to use a physics engine to counter this? If I don't want to use physics, how do I go about this? Do these two posts provide an answer:

http://www.chandlerprall.com/2012/06/requestanimationframe-is-not-your-logics-friend/

http://impactjs.com/forums/impact-engine/misuse-of-requestanimationframe

 

...if yes, how do I do this (properly) in Phaser? Is something like this already in place?

 

Thanks, best regards,

mIHA

Link to comment
Share on other sites

@Noid: Oh, great :) I will take a look at that. Thanks!

 

UPDATE: Indeed the case. I am looking at the code. The core game loop executes two separate functions, updateLogic and updateRender. These two, among other things, call state.update and state.render, respectively. If I understand this correctly, state.render is called once per requestAnimationFrame, while state.update is called game.time.desiredFps times per second (desiredFps is 60 by default).

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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