Jump to content

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

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 post
Share on other sites


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.



Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...