Skip to content

Commit cccaa30

Browse files
Dan CoxDan Cox
authored andcommitted
CocoonJSApp 'onSuspended' and 'onActivated' events
This PR depends on [phaserjs#1150] (phaserjs#1150)! (I apologize for all the different pull requests in a short time period. I finally got some time to do some development tonight and have been making my way through many of my TODO items.) This adds support for CocoonJS.App's 'onSuspended' and 'onActivated' events, making it so that the timers and sounds are stopped/started and muted/unmuted when the user swaps an app from the background to the fore or the reverse. Because neither ['onActivated'] (http://doc.ludei.com/2.0.2/CocoonJS_App/symbols/CocoonJS.App.html#.event:onActivated) nor ['onSuspended'] (http://doc.ludei.com/2.0.2/CocoonJS_App/symbols/CocoonJS.App.html#.event:onSuspended) send an Event object themselves, this patch fakes sending an object by creating one during the function call and giving it a 'type' property for visibilityChange() to check against.
1 parent da5a948 commit cccaa30

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/core/Stage.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,18 @@ Phaser.Stage.prototype.checkVisibility = function () {
298298

299299
window.onblur = this._onChange;
300300
window.onfocus = this._onChange;
301+
302+
var _this = this;
303+
304+
if(this.game.device.cocoonJSApp)
305+
{
306+
CocoonJS.App.onSuspended.addEventListener(function () {
307+
Phaser.Stage.prototype.visibilityChange.call(_this, {type: "pause"});
308+
});
309+
CocoonJS.App.onActivated.addEventListener(function () {
310+
Phaser.Stage.prototype.visibilityChange.call(_this, {type: "resume"});
311+
});
312+
}
301313

302314
};
303315

@@ -328,7 +340,7 @@ Phaser.Stage.prototype.visibilityChange = function (event) {
328340
return;
329341
}
330342

331-
if (document.hidden || document.mozHidden || document.msHidden || document.webkitHidden)
343+
if (document.hidden || document.mozHidden || document.msHidden || document.webkitHidden || event.type === "pause")
332344
{
333345
this.game.gamePaused(event);
334346
}

0 commit comments

Comments
 (0)