diff --git a/src/core/StateManager.js b/src/core/StateManager.js index 33c39ea4d..9f0bfeb49 100644 --- a/src/core/StateManager.js +++ b/src/core/StateManager.js @@ -332,15 +332,11 @@ Phaser.StateManager.prototype = { { if (this._pendingState && this.game.isBooted) { - var previousStateKey = this.current; - // Already got a state running? this.clearCurrentState(); this.setCurrentState(this._pendingState); - this.onStateChange.dispatch(this.current, previousStateKey); - if (this.current !== this._pendingState) { return; @@ -527,6 +523,7 @@ Phaser.StateManager.prototype = { */ setCurrentState: function (key) { + var previousStateKey = this.current; var state = this.states[key]; this.callbackContext = state; @@ -561,6 +558,8 @@ Phaser.StateManager.prototype = { this.current = key; this._created = false; + this.onStateChange.dispatch(this.current, previousStateKey); + // At this point key and pendingState should equal each other this.onInitCallback.apply(this.callbackContext, this._args);