From be4d42a1c2dc82f6f8a01dc7680a9bdd0d993557 Mon Sep 17 00:00:00 2001 From: photonstorm Date: Sat, 22 Feb 2014 00:01:19 +0000 Subject: [PATCH] The StateManager now looks for a function called 'resumed' which is called when a game un-pauses (fixes #358) --- README.md | 1 + src/core/StateManager.js | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9d3db635..d0bc9c1f 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,7 @@ New features: * Tilemap.createCollisionObjects will parse Tiled data for objectgroups and convert polyline instances into physics objects you can collide with in the world. * Loader can now load JSON files specifically (game.load.json) and they are parsed and stored in the Game.Cache. Retrieve with game.cache.getJSON(key). * TileSprites can now receive full Input events, dragging, etc and be positioned in-world and fixed to cameras. +* The StateManager now looks for a function called 'resumed' which is called when a game un-pauses. Updates: diff --git a/src/core/StateManager.js b/src/core/StateManager.js index 77378f61..1a29948f 100644 --- a/src/core/StateManager.js +++ b/src/core/StateManager.js @@ -93,6 +93,11 @@ Phaser.StateManager = function (game, pendingState) { */ this.onPausedCallback = null; + /** + * @property {function} onResumedCallback - This will be called when the state is resumed from a paused state. + */ + this.onResumedCallback = null; + /** * @property {function} onShutDownCallback - This will be called when the state is shut down (i.e. swapped to another state). */ @@ -195,6 +200,7 @@ Phaser.StateManager.prototype = { this.onUpdateCallback = null; this.onRenderCallback = null; this.onPausedCallback = null; + this.onResumedCallback = null; this.onDestroyCallback = null; } @@ -370,6 +376,7 @@ Phaser.StateManager.prototype = { this.onPreRenderCallback = this.states[key]['preRender'] || null; this.onRenderCallback = this.states[key]['render'] || null; this.onPausedCallback = this.states[key]['paused'] || null; + this.onResumedCallback = this.states[key]['resumed'] || null; // Used when the state is no longer the current active state this.onShutDownCallback = this.states[key]['shutdown'] || this.dummy; @@ -418,7 +425,7 @@ Phaser.StateManager.prototype = { if (this._created && this.onPausedCallback) { - this.onPausedCallback.call(this.callbackContext, this.game, true); + this.onPausedCallback.call(this.callbackContext, this.game); } }, @@ -429,9 +436,9 @@ Phaser.StateManager.prototype = { */ resume: function () { - if (this._created && this.onre) + if (this._created && this.onResumedCallback) { - this.onPausedCallback.call(this.callbackContext, this.game, false); + this.onResumedCallback.call(this.callbackContext, this.game); } }, @@ -518,6 +525,7 @@ Phaser.StateManager.prototype = { this.onUpdateCallback = null; this.onRenderCallback = null; this.onPausedCallback = null; + this.onResumedCallback = null; this.onDestroyCallback = null; this.game = null;