Skip to content

Commit

Permalink
Merge branch 'breaking/onStateChange-order'
Browse files Browse the repository at this point in the history
  • Loading branch information
samme committed May 29, 2020
2 parents bdf8be1 + 7125ce9 commit 66da707
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/core/StateManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -527,6 +523,7 @@ Phaser.StateManager.prototype = {
*/
setCurrentState: function (key)
{
var previousStateKey = this.current;
var state = this.states[key];

this.callbackContext = state;
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 66da707

Please sign in to comment.