mirror of
https://github.com/photonstorm/phaser
synced 2025-02-17 06:28:30 +00: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:
parent
86374d4437
commit
4d284029c7
6 changed files with 114 additions and 20 deletions
|
@ -173,6 +173,9 @@ Bug Fixes:
|
|||
* Fixed issue stopping SoundManager.volume from working correctly on a global volume basis (fixes #488)
|
||||
* Phaser.Timer will no longer create negative ticks during game boot, no matter how small the Timer delay is (fixes #366)
|
||||
* Phaser.Timer will no longer resume if it was previously paused and the game loses focus and then resumes (fixes #383)
|
||||
* 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.
|
||||
|
||||
|
||||
|
||||
TO DO:
|
||||
|
|
|
@ -23,21 +23,36 @@ function create() {
|
|||
|
||||
anim.play(10, true);
|
||||
|
||||
game.onPause.add(paused, this);
|
||||
game.onResume.add(resumed, this);
|
||||
// game.onPause.add(paused, this);
|
||||
// game.onResume.add(resumed, this);
|
||||
|
||||
t = game.add.tween(mummy).to({x:700}, 15000, Phaser.Easing.Linear.None, true);
|
||||
t.onComplete.add(tweenOver, this);
|
||||
|
||||
s.push('starting: ' + game.stage._hiddenVar);
|
||||
|
||||
game.input.onDown.add(pauseTween, this);
|
||||
|
||||
}
|
||||
|
||||
function pauseTween(pointer) {
|
||||
|
||||
if (pointer.x < 400)
|
||||
{
|
||||
t.pause();
|
||||
}
|
||||
else
|
||||
{
|
||||
t.resume();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function tweenOver() {
|
||||
console.log('yay all over after 15 seconds anyway');
|
||||
}
|
||||
|
||||
function pauseToggle() {
|
||||
/*function pauseToggle() {
|
||||
|
||||
if (game.paused)
|
||||
{
|
||||
|
@ -49,7 +64,6 @@ function pauseToggle() {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
function paused() {
|
||||
|
||||
s.push('paused now: ' + game.time.now);
|
||||
|
@ -64,6 +78,7 @@ function resumed() {
|
|||
s.push('pause duration: ' + game.time.pauseDuration);
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
function update() {
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
},
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue