totallybueno

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?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.