mirror of
https://github.com/wassname/phaser.git
synced 2026-08-04 13:14:14 +08:00
Tweens now resume correctly if the game pauses (focus loss) while they are paused.
Tweens don't double pause if they were already paused and the game pauses.
This commit is contained in:
+2
-2
@@ -219,7 +219,7 @@ Phaser.Time.prototype = {
|
||||
|
||||
for (var i = 0; i < this._timers.length; i++)
|
||||
{
|
||||
this._timers[i]._timeResume();
|
||||
this._timers[i]._resume();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -299,7 +299,7 @@ Phaser.Time.prototype = {
|
||||
|
||||
while (i--)
|
||||
{
|
||||
this._timers[i]._timePause();
|
||||
this._timers[i]._pause();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
+8
-6
@@ -425,10 +425,11 @@ Phaser.Timer.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Pauses the Timer and all events in the queue.
|
||||
* @method Phaser.Timer#_timePause
|
||||
* This is called by the core Game loop. Do not call it directly, instead use Timer.pause.
|
||||
* @method Phaser.Timer#_pause
|
||||
* @private
|
||||
*/
|
||||
_timePause: function () {
|
||||
_pause: function () {
|
||||
|
||||
if (this.running && !this.expired)
|
||||
{
|
||||
@@ -463,10 +464,11 @@ Phaser.Timer.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Resumes the Timer and updates all pending events.
|
||||
* @method Phaser.Timer#_timeResume
|
||||
* This is called by the core Game loop. Do not call it directly, instead use Timer.pause.
|
||||
* @method Phaser.Timer#_resume
|
||||
* @private
|
||||
*/
|
||||
_timeResume: function () {
|
||||
_resume: function () {
|
||||
|
||||
if (this._codePaused)
|
||||
{
|
||||
|
||||
+49
-5
@@ -132,6 +132,13 @@ Phaser.Tween = function (object, game) {
|
||||
*/
|
||||
this._onUpdateCallbackContext = null;
|
||||
|
||||
/**
|
||||
* @property {boolean} _paused - Is this Tween paused or not?
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
this._paused = false;
|
||||
|
||||
/**
|
||||
* @property {number} _pausedTime - Private pause timer.
|
||||
* @private
|
||||
@@ -139,6 +146,12 @@ Phaser.Tween = function (object, game) {
|
||||
*/
|
||||
this._pausedTime = 0;
|
||||
|
||||
/**
|
||||
* @property {boolean} _codePaused - Was the Tween paused by code or by Game focus loss?
|
||||
* @private
|
||||
*/
|
||||
this._codePaused = false;
|
||||
|
||||
/**
|
||||
* @property {boolean} pendingDelete - If this tween is ready to be deleted by the TweenManager.
|
||||
* @default
|
||||
@@ -436,28 +449,59 @@ Phaser.Tween.prototype = {
|
||||
*/
|
||||
pause: function () {
|
||||
|
||||
this._codePaused = true;
|
||||
this._paused = true;
|
||||
this._pausedTime = this.game.time.now;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* This is called by the core Game loop. Do not call it directly, instead use Tween.pause.
|
||||
* @method Phaser.Tween#_pause
|
||||
* @private
|
||||
*/
|
||||
_pause: function () {
|
||||
|
||||
if (!this._codePaused)
|
||||
{
|
||||
this._paused = true;
|
||||
this._pausedTime = this.game.time.now;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Resumes a paused tween.
|
||||
*
|
||||
* @method Phaser.Tween#resume
|
||||
* @param {boolean} [fromManager=false] - Did this resume request come from the TweenManager or game code?
|
||||
*/
|
||||
resume: function (fromManager) {
|
||||
resume: function () {
|
||||
|
||||
this._paused = false;
|
||||
|
||||
if (typeof fromManager === 'undefined' || !fromManager)
|
||||
if (this._paused)
|
||||
{
|
||||
this._paused = false;
|
||||
this._codePaused = false;
|
||||
|
||||
this._startTime += (this.game.time.now - this._pausedTime);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* This is called by the core Game loop. Do not call it directly, instead use Tween.pause.
|
||||
* @method Phaser.Tween#_resume
|
||||
* @private
|
||||
*/
|
||||
_resume: function () {
|
||||
|
||||
if (this._codePaused)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._startTime += this.game.time.pauseDuration;
|
||||
this._paused = false;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
@@ -39,8 +39,8 @@ Phaser.TweenManager = function (game) {
|
||||
*/
|
||||
this._add = [];
|
||||
|
||||
this.game.onPause.add(this.pauseAll, this);
|
||||
this.game.onResume.add(this.resumeAll, this);
|
||||
this.game.onPause.add(this._pauseAll, this);
|
||||
this.game.onResume.add(this._resumeAll, this);
|
||||
|
||||
};
|
||||
|
||||
@@ -171,6 +171,36 @@ Phaser.TweenManager.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Private. Called by game focus loss. Pauses all currently running tweens.
|
||||
*
|
||||
* @method Phaser.TweenManager#_pauseAll
|
||||
* @private
|
||||
*/
|
||||
_pauseAll: function () {
|
||||
|
||||
for (var i = this._tweens.length - 1; i >= 0; i--)
|
||||
{
|
||||
this._tweens[i]._pause();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Private. Called by game focus loss. Resumes all currently paused tweens.
|
||||
*
|
||||
* @method Phaser.TweenManager#_resumeAll
|
||||
* @private
|
||||
*/
|
||||
_resumeAll: function () {
|
||||
|
||||
for (var i = this._tweens.length - 1; i >= 0; i--)
|
||||
{
|
||||
this._tweens[i]._resume();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Pauses all currently running tweens.
|
||||
*
|
||||
@@ -186,7 +216,7 @@ Phaser.TweenManager.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Pauses all currently paused tweens.
|
||||
* Resumes all currently paused tweens.
|
||||
*
|
||||
* @method Phaser.TweenManager#resumeAll
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user