Jump to content

codepaused property


devin
 Share

Recommended Posts

In the phaser 2.0.5 code, I see the paused property defined as:

Object.defineProperty(Phaser.Game.prototype, "paused", {    get: function () {        return this._paused;    },    set: function (value) {        if (value === true)        {            if (this._paused === false)            {                this._paused = true;                this._codePaused = true;                this.sound.setMute();                this.time.gamePaused();                this.onPause.dispatch(this);            }        }        else        {            if (this._paused)            {                this._paused = false;                this._codePaused = false;                this.input.reset();                this.sound.unsetMute();                this.time.gameResumed();                this.onResume.dispatch(this);            }        }    }});

One place this._codePaused is used in:

//stage code:gameResumed: function (event) {        //  Game is paused, but wasn't paused via code, so resume it        if (this._paused && !this._codePaused)        {            this._paused = false;            this.time.gameResumed();            this.input.reset();            this.sound.unsetMute();            this.onResume.dispatch(event);        }    },

I'm thinking the property should be modified to:

Object.defineProperty(Phaser.Game.prototype, "paused", {    get: function () {        return this._paused;    },    set: function (value) {        if (value === true)        {            if (this._paused === false)            {                this._paused = true;                this.sound.setMute();                this.time.gamePaused();                this.onPause.dispatch(this);            }            this._codePaused = true;        }        else        {            if (this._paused)            {                this._paused = false;                this.input.reset();                this.sound.unsetMute();                this.time.gameResumed();                this.onResume.dispatch(this);            }            this._codePaused = false;        }    }});

My scenario is this. When my game loses focus, it pauses automatically. However, when it returns focus, it automatically unpauses. I want it to stay paused with a menu up. In my pauseUpdate function, I have this.game.paused = true;, but since it is already paused not via the code, it won't set _codePaused = true;

 

At the moment, I'm hacking it adding this.game._codePaused = true; in my pauseUpdate function so that the game won't automatically start up after focus is returned.

 

Was the above intended functionality, is there a better way to do what I'm doing, or does the code sound good? thoughts?

 

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...