Jump to content

Pause on device lock - iOS


JoseDu
 Share

Recommended Posts

Hi everyone,

is there any way how to detect and pause game when iOS (7) device is locked?

When I lock my device during the game, it still runs on background. It also happens when I leave browser (Safari, Chrome) with the home button and then resume. Everything works fine on Android devices or when I switch tabs on iOS.

 

I have "disableVisibilityChange" set to "false" and pausing the game with the "this.game.onPause" event.

You can play the game on: http://brainie.strangevillage.com/brainie_test/

 

Thanks!

Link to comment
Share on other sites

Just to say that I did a huge load of work on improving the way the visibility api is handled today and this is now working as expected across desktop and mobile. I've tested on iOS7 and it's pausing properly when you jump between tabs, close to the home screen or the iPad locks. This is all in the 1.2 branch right now and will be released in the next update. If you needed to you could probably extract the new code from core/Stage.js and merge with the current version of Phaser.

Link to comment
Share on other sites

  • 3 weeks later...

Hey there - just want to continue this topic as I'm trying to do some onPause/onResume stuff right now and I'm not getting the behaviour of onPause triggering when I go to the home screen or lock the device (iPhone 5, iOS 7.1). Works like a dream on switching tabs in Mobile Safari, and works perfectly in all situations I could think of for laptop browser (Chrome).

 

Am I missing something, or is this just in flux in 1.2?

Link to comment
Share on other sites

Oh yeah? Hmmm, that's odd then. It may be something with me as I see I'm not getting the trigger on an iPad 2 running OS 7.0.5 (I think - certainly pre 7.1) either... so maybe it's my code.

 

So all I'm doing is setting visibility checking in Boot.js

this.stage.disableVisibilityChange = false;

and then in the create function in my Game.js

this.game.onPause.add(this.onGamePause,this);this.game.onResume.add(this.onGameResume,this);

And this triggers from all forms of focus loss on my laptop's browser, and for tab changes in mobile Safari, but never for screen lock or for hitting the home button on my iPhone 5 or my iPad 2. Am I just doing something stupid? Would love it if I were!

 

(For now, by the way, my particular need is also met by the usual thing off setting a looping check to see whether more time has elapsed than "should have" because the page has been put to sleep by the OS/Browser.)

Link to comment
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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

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