Jump to content

Best practice for pause/unpause on canvas focus/blur?


totallybueno
 Share

Recommended Posts

Hi there,

everytime I have to make a game that pauses when the canvas loses the focus (jquery blur()) I struggle with lines and lines of stupid lines of javascript and I´m pretty sure there´s something simpler than my way to do that. I have a normal sprite on the game that pauses/unpauses the game, and I would like to do exactly the same when the canvas focus/blur... how do you guys handle this?

Link to comment
Share on other sites

Hi,

in Phaser's examples there is an interesting script about the "pause option":  http://phaser.io/examples/v2/misc/pause-menu

personally (this is only my preference) I use a simple flag to pause the game:

  • in the "update" section of the game, when the flag is 1, then check collisions, move sprites using buttons, check when keyboard is pressed, etc.etc.
  • when the flag is 2, then "make something else" (like a message on screen), so all previous action are "freezed"   :)
  • everithing come to normal when the flag come back to 1

but, remember, this is only my personal preference.

I suppose there are other options.

Bye,

Alex

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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