eran Posted November 9, 2015 Share Posted November 9, 2015 I use game.onPause.add(myPauseFunction) but this does not detect an incoming call.I'm doing a race game in Phaser and would like to pause the race on incoming call.any idea how to get this event on Phaser / JS? HAFID 1 Link to comment Share on other sites More sharing options...
in mono Posted November 9, 2015 Share Posted November 9, 2015 If running in a browser, it will most probably lose focus when a call comes. game.onPause.add() will add a callback for when you do pause your game, but won't initiate the pause itself. As for the focus, try something like this:window.onblur = function() { console.log("lost focus"); // Pause} Link to comment Share on other sites More sharing options...
eran Posted November 9, 2015 Author Share Posted November 9, 2015 Thanks. Tried this with no success ;(I receive the window.onblur event in my client when pressing the home button in my iPhone, but not when a call is coming in..It might be that the browser doesn't lose focus, or is there another event worth trying? Link to comment Share on other sites More sharing options...
ekeimaja Posted November 9, 2015 Share Posted November 9, 2015 I would wrap game with if(game.is.active){ //code here }. Link to comment Share on other sites More sharing options...
eran Posted November 9, 2015 Author Share Posted November 9, 2015 thanks. what should the actual syntax be for "game.is.active"?also, I believe that the game is active, as it doesn't pause. Link to comment Share on other sites More sharing options...
ekeimaja Posted November 9, 2015 Share Posted November 9, 2015 Try this:if (this.game.input.activePointer) { }On me game pauses immediately, when mouse is outside of game area. Link to comment Share on other sites More sharing options...
eran Posted November 9, 2015 Author Share Posted November 9, 2015 I tried this, also with no success. Just so we'll be on the same page - does this solution relate to the case of playing on mobile and receiving a call? Link to comment Share on other sites More sharing options...
ekeimaja Posted November 10, 2015 Share Posted November 10, 2015 Can you show your code, so we can help you better? Link to comment Share on other sites More sharing options...
eran Posted November 10, 2015 Author Share Posted November 10, 2015 Sure. I gathered the relevant parts:This is put in the create: game.onPause.add(pauseGame, game);pauseGame() - is a global function that does some things and sets - game.paused = true; The onPause is triggered when I minimize the browser on my phone, move tab on my desktop and some other cases - so I managed to get the pauseGame() function working in these case.The thing is that game.onPause.add(...) is not triggered on receiving the call. I also tried capturing the following events when call is received, using addEventListener() - onpageshow, onpagehide, onblur, onfocus, onfocusin, onfocusout, and more.. no success ;( Thank you for the interest and help!! Link to comment Share on other sites More sharing options...
pog Posted November 10, 2015 Share Posted November 10, 2015 So the update call is still happening while on a phone call? Maybe you can put something in the render function of your game loop. You will need to test if the render function is also being called during the phone call. If the render isn't called for about 5 updates then you're not the active app. function update(){ ticks++; if(ticks > 5){ pause(); }}function render(){ ticks = 0;}I haven't tested this, just throwing ideas out there Link to comment Share on other sites More sharing options...
chongdashu Posted November 11, 2015 Share Posted November 11, 2015 Have you tried the Page Visibility API? More specifically, listening for the "visibilitychange" event?//startSimulation and pauseSimulation defined elsewherefunction handleVisibilityChange() { if (document.hidden) { pauseSimulation(); } else { startSimulation(); }}document.addEventListener("visibilitychange", handleVisibilityChange, false);Source MichaelD 1 Link to comment Share on other sites More sharing options...
Recommended Posts