Added ability for the TimeManager to monitor the pause duration. This is then applied to tweens and other game services, meaning the tweens now restart properly after a pause resumes.

This commit is contained in:
Richard Davey 2013-08-08 05:43:22 +01:00
parent 5768336150
commit ab7e55ef27
12 changed files with 358 additions and 149 deletions

View file

@ -88,12 +88,6 @@ module Phaser {
*/
public _raf: RequestAnimationFrame;
/**
* Milliseconds of time per step of the game loop.
* @type {number}
*/
//private _step: number = 0;
/**
* Whether load complete loading or not.
* @type {boolean}
@ -183,6 +177,18 @@ module Phaser {
*/
public onDestroyCallback = null;
/**
* This Signal is dispatched whenever the game pauses.
* @type {Phaser.Signal}
*/
public onPause: Phaser.Signal;
/**
* This Signal is dispatched whenever the game resumes from a paused state.
* @type {Phaser.Signal}
*/
public onResume: Phaser.Signal;
/**
* Reference to the GameObject Factory.
* @type {GameObjectFactory}
@ -307,6 +313,9 @@ module Phaser {
document.removeEventListener('DOMContentLoaded', Phaser.GAMES[this.id].boot);
window.removeEventListener('load', Phaser.GAMES[this.id].boot);
this.onPause = new Phaser.Signal;
this.onResume = new Phaser.Signal;
this.device = new Device();
this.net = new Net(this);
this.math = new GameMath(this);
@ -365,24 +374,6 @@ module Phaser {
}
public setRenderer(type: number) {
switch (type)
{
case Phaser.Types.RENDERER_AUTO_DETECT:
this.renderer = new Phaser.Renderer.Headless.HeadlessRenderer(this);
break;
case Phaser.Types.RENDERER_AUTO_DETECT:
case Phaser.Types.RENDERER_CANVAS:
this.renderer = new Phaser.Renderer.Canvas.CanvasRenderer(this);
break;
// WebGL coming soon :)
}
}
/**
* Called when the load has finished after preload was run.
*/
@ -513,6 +504,24 @@ module Phaser {
}
public setRenderer(type: number) {
switch (type)
{
case Phaser.Types.RENDERER_AUTO_DETECT:
this.renderer = new Phaser.Renderer.Headless.HeadlessRenderer(this);
break;
case Phaser.Types.RENDERER_AUTO_DETECT:
case Phaser.Types.RENDERER_CANVAS:
this.renderer = new Phaser.Renderer.Canvas.CanvasRenderer(this);
break;
// WebGL coming soon :)
}
}
/**
* Set the most common state callbacks (init, create, update, render).
* @param preloadCallback {function} Init callback invoked when init state.
@ -675,13 +684,16 @@ module Phaser {
if (value == true && this._paused == false)
{
this._paused = true;
this.onPause.dispatch();
// Hook to the above
this.sound.pauseAll();
this._raf.callback = this.pausedLoop;
}
else if (value == false && this._paused == true)
{
this._paused = false;
//this.time.time = window.performance.now ? (performance.now() + performance.timing.navigationStart) : Date.now();
this.onResume.dispatch();
// Hook to the above
this.input.reset();
this.sound.resumeAll();

View file

@ -290,6 +290,8 @@ module Phaser {
public pauseGame() {
this.game.paused = true;
if (this.disablePauseScreen == false && this.pauseScreen)
{
this.pauseScreen.onPaused();
@ -297,8 +299,6 @@ module Phaser {
this.saveCanvasValues();
this.game.paused = true;
}
public resumeGame() {

View file

@ -24,6 +24,9 @@ module Phaser {
this._timeLastSecond = this._started;
this.time = this._started;
this.game.onPause.add(this.gamePaused, this);
this.game.onResume.add(this.gameResumed, this);
}
/**
@ -42,7 +45,7 @@ module Phaser {
* Set it to 0.5 for slow motion, to 2.0 makes game twice faster.
* @type {number}
*/
public timeScale: number = 1.0;
//public timeScale: number = 1.0;
/**
* Elapsed since last frame.
@ -57,6 +60,13 @@ module Phaser {
*/
public time: number = 0;
/**
* How long the game has been paused for. Gets reset each time the game pauses.
* @property pausedTime
* @type {number}
*/
public pausedTime: number = 0;
/**
* Time of current frame.
* @property now
@ -101,13 +111,13 @@ module Phaser {
public fpsMax: number = 0;
/**
* Mininal duration between 2 frames.
* Minimum duration between 2 frames.
* @type {number}
*/
public msMin: number = 1000;
/**
* Maximal duration between 2 frames.
* Maximum duration between 2 frames.
* @type {number}
*/
public msMax: number = 0;
@ -133,7 +143,6 @@ module Phaser {
public update(raf: number) {
this.now = raf; // mark
//this.now = Date.now(); // mark
this.delta = this.now - this.time; // elapsedMS
this.msMin = Math.min(this.msMin, this.delta);
@ -153,8 +162,26 @@ module Phaser {
this.time = this.now; // _total
// Paused?
if (this.game.paused)
{
this.pausedTime = this.now - this._pauseStarted;
}
}
private gamePaused() {
this._pauseStarted = this.now;
}
private gameResumed() {
// Level out the delta timer to avoid spikes
this.pauseDuration = this.pausedTime;
}
public pauseDuration: number = 0;
private _pauseStarted: number = 0;
/**
* How long has passed since given time.
* @method elapsedSince
@ -168,7 +195,7 @@ module Phaser {
}
/**
* How long has passed since give time (in seconds).
* How long has passed since the given time (in seconds).
* @method elapsedSecondsSince
* @param {number} since The time you want to measure (in seconds).
* @return {number} Duration between given time and now (in seconds).

View file

@ -60,6 +60,7 @@ module Phaser {
* @type {object}
*/
private _object = null;
private _pausedTime: number = 0;
/**
@ -344,6 +345,19 @@ module Phaser {
}
public pause() {
this._paused = true;
}
public resume() {
this._paused = false;
this._startTime += this.game.time.pauseDuration;
}
private _paused: bool;
/**
* Update tweening.
* @param time {number} Current time from game clock.
@ -351,24 +365,7 @@ module Phaser {
*/
public update(time) {
if (this.game.paused == true)
{
if (this._pausedTime == 0)
{
this._pausedTime = time;
}
}
else
{
// Ok we aren't paused, but was there some time gained?
if (this._pausedTime > 0)
{
this._startTime += (time - this._pausedTime);
this._pausedTime = 0;
}
}
if (time < this._startTime)
if (this._paused || time < this._startTime)
{
return true;
}

View file

@ -22,8 +22,12 @@ module Phaser {
constructor(game: Phaser.Game) {
this.game = game;
this._tweens = [];
this.game.onPause.add(this.pauseAll, this);
this.game.onResume.add(this.resumeAll, this);
}
/**
@ -140,5 +144,41 @@ module Phaser {
}
public pauseAll() {
if (this._tweens.length === 0)
{
return false;
}
var i = 0;
var numTweens = this._tweens.length;
while (i < numTweens)
{
this._tweens[i].pause();
i++;
}
}
public resumeAll() {
if (this._tweens.length === 0)
{
return false;
}
var i = 0;
var numTweens = this._tweens.length;
while (i < numTweens)
{
this._tweens[i].resume();
i++;
}
}
}
}

View file

@ -22,23 +22,19 @@ Known Issues
* Input detection on Sprites/Buttons doesn't work if the CAMERA is rotated or scaled.
Future Plans
------------
Latest Update
-------------
TODO:
* Inject game into a <div>
* Ability to layer another DOM object and have it controlled by the game somehow. Can then do stacked canvas effects.
* Add ability to create extra <div>s within the game container, layered above/below the canvas
* Rename init to preload and call start automatically
* Allow camera to directly render to the stage rather than its hidden (maybe does this by default? or have under Mobile Optimisations list)
* Basic Window UI component (maybe a propogating Group?)
ToDo before release
-------------------
* Investigate why tweens don't restart after the game pauses
* Hook sound/input to the pause/resume signals
* Fix bug in Tween yoyo + loop combo
* Check that tween pausing works with the new performance.now
* Game.Time should monitor pause duration
* Allow camera to directly render to the stage rather than hidden ctx (maybe does this by default? or have under Mobile Optimisations list)
* Investigate bug re: tilemap collision and animation frames
* Add clip support + shape options to Texture Component.
* Need to be able to set the current tilemap layer, then the getTileXY default layer uses that one if no other given
@ -48,18 +44,16 @@ TODO:
* Tilemap.render - move layers length to var
* Tilemap.destroy needs doing
* Sprite.transform.bottomRight/Left doesn't seem to take origin into account
* Stage.opaqueBackground = 'rgb()' or null, alpha, blendMode, filters, mask, rotation+XYZ,scaleXYZ,visible
* Stage CSS3 Transforms?
* Ability to layer another DOM object and have it controlled by the game somehow. Can then do stacked canvas effects.
* Stage lost to mute
* Bitmap Font support
* Basic Window component (maybe a propogating Group?)
* Put ArcadePhysics back in
* Look at the N+ tile support maybe with ArcadePhysics?
* Pixel-perfect click check
* Check Flash atlas export is supported
* DynamicTexture.setPixel needs to be swapped for a proper pixel put, not the filledRect it currently is.
Latest Update
-------------
V1.0.0
@ -165,7 +159,8 @@ V1.0.0
* Added the new PluginManager. Moved all the Camera FX over to plugins. Everything will be a plugin from now on.
* Added Sprite.transform.centerOn(x,y) to quickly center a sprite on a coordinate without messing with the sprite origin and regardless of rotation.
* Added Input.pollRate - this lets you limit how often Pointer events are handled (0 = every frame, 1 = every other frame, etc)
* Renamed the 'init' function to 'preload' and now call load.start automatically.
* Renamed the 'init' function to 'preload'. It now calls load.start automatically.
* Added
V0.9.6

View file

@ -395,6 +395,10 @@
<Content Include="tweens\easing example 4.ts" />
<Content Include="tweens\easing example 5.ts" />
<Content Include="tweens\easing example 6.ts" />
<TypeScriptCompile Include="tweens\pause test.ts" />
<Content Include="tweens\pause test.js">
<DependentUpon>pause test.ts</DependentUpon>
</Content>
<Content Include="tweens\tween loop 1.js">
<DependentUpon>tween loop 1.ts</DependentUpon>
</Content>

View file

@ -10693,24 +10693,20 @@ var Phaser;
this._chainedTweens.push(tween);
return this;
};
Tween.prototype.pause = function () {
this._paused = true;
};
Tween.prototype.resume = function () {
this._paused = false;
this._startTime += this.game.time.pauseDuration;
};
Tween.prototype.update = /**
* Update tweening.
* @param time {number} Current time from game clock.
* @return {boolean} Return false if this completed and no need to update, otherwise return true.
*/
function (time) {
if(this.game.paused == true) {
if(this._pausedTime == 0) {
this._pausedTime = time;
}
} else {
// Ok we aren't paused, but was there some time gained?
if(this._pausedTime > 0) {
this._startTime += (time - this._pausedTime);
this._pausedTime = 0;
}
}
if(time < this._startTime) {
if(this._paused || time < this._startTime) {
return true;
}
this._tempElapsed = (time - this._startTime) / this._duration;
@ -14192,11 +14188,11 @@ var Phaser;
this.canvas.style['-ms-interpolation-mode'] = 'nearest-neighbor';
};
Stage.prototype.pauseGame = function () {
this.game.paused = true;
if(this.disablePauseScreen == false && this.pauseScreen) {
this.pauseScreen.onPaused();
}
this.saveCanvasValues();
this.game.paused = true;
};
Stage.prototype.resumeGame = function () {
if(this.disablePauseScreen == false && this.pauseScreen) {
@ -14336,7 +14332,7 @@ var Phaser;
* Set it to 0.5 for slow motion, to 2.0 makes game twice faster.
* @type {number}
*/
this.timeScale = 1.0;
//public timeScale: number = 1.0;
/**
* Elapsed since last frame.
* @type {number}
@ -14349,6 +14345,12 @@ var Phaser;
*/
this.time = 0;
/**
* How long the game has been paused for. Gets reset each time the game pauses.
* @property pausedTime
* @type {number}
*/
this.pausedTime = 0;
/**
* Time of current frame.
* @property now
* @type {number}
@ -14376,12 +14378,12 @@ var Phaser;
*/
this.fpsMax = 0;
/**
* Mininal duration between 2 frames.
* Minimum duration between 2 frames.
* @type {number}
*/
this.msMin = 1000;
/**
* Maximal duration between 2 frames.
* Maximum duration between 2 frames.
* @type {number}
*/
this.msMax = 0;
@ -14395,10 +14397,14 @@ var Phaser;
* @type {number}
*/
this._timeLastSecond = 0;
this.pauseDuration = 0;
this._pauseStarted = 0;
this.game = game;
this._started = 0;
this._timeLastSecond = this._started;
this.time = this._started;
this.game.onPause.add(this.gamePaused, this);
this.game.onResume.add(this.gameResumed, this);
}
Object.defineProperty(TimeManager.prototype, "totalElapsedSeconds", {
get: /**
@ -14421,7 +14427,6 @@ var Phaser;
function (raf) {
this.now = raf// mark
;
//this.now = Date.now(); // mark
this.delta = this.now - this.time// elapsedMS
;
this.msMin = Math.min(this.msMin, this.delta);
@ -14436,6 +14441,17 @@ var Phaser;
}
this.time = this.now// _total
;
// Paused?
if(this.game.paused) {
this.pausedTime = this.now - this._pauseStarted;
}
};
TimeManager.prototype.gamePaused = function () {
this._pauseStarted = this.now;
};
TimeManager.prototype.gameResumed = function () {
// Level out the delta timer to avoid spikes
this.pauseDuration = this.pausedTime;
};
TimeManager.prototype.elapsedSince = /**
* How long has passed since given time.
@ -14447,7 +14463,7 @@ var Phaser;
return this.now - since;
};
TimeManager.prototype.elapsedSecondsSince = /**
* How long has passed since give time (in seconds).
* How long has passed since the given time (in seconds).
* @method elapsedSecondsSince
* @param {number} since The time you want to measure (in seconds).
* @return {number} Duration between given time and now (in seconds).
@ -14487,6 +14503,8 @@ var Phaser;
function TweenManager(game) {
this.game = game;
this._tweens = [];
this.game.onPause.add(this.pauseAll, this);
this.game.onResume.add(this.resumeAll, this);
}
TweenManager.prototype.getAll = /**
* Get all the tween objects in an array.
@ -14560,6 +14578,28 @@ var Phaser;
}
return true;
};
TweenManager.prototype.pauseAll = function () {
if(this._tweens.length === 0) {
return false;
}
var i = 0;
var numTweens = this._tweens.length;
while(i < numTweens) {
this._tweens[i].pause();
i++;
}
};
TweenManager.prototype.resumeAll = function () {
if(this._tweens.length === 0) {
return false;
}
var i = 0;
var numTweens = this._tweens.length;
while(i < numTweens) {
this._tweens[i].resume();
i++;
}
};
return TweenManager;
})();
Phaser.TweenManager = TweenManager;
@ -18419,11 +18459,6 @@ var Phaser;
if (typeof destroyCallback === "undefined") { destroyCallback = null; }
var _this = this;
/**
* Milliseconds of time per step of the game loop.
* @type {number}
*/
//private _step: number = 0;
/**
* Whether load complete loading or not.
* @type {boolean}
*/
@ -18532,6 +18567,8 @@ var Phaser;
} else {
document.removeEventListener('DOMContentLoaded', Phaser.GAMES[this.id].boot);
window.removeEventListener('load', Phaser.GAMES[this.id].boot);
this.onPause = new Phaser.Signal();
this.onResume = new Phaser.Signal();
this.device = new Phaser.Device();
this.net = new Phaser.Net(this);
this.math = new Phaser.GameMath(this);
@ -18574,18 +18611,6 @@ var Phaser;
}
}
};
Game.prototype.setRenderer = function (type) {
switch(type) {
case Phaser.Types.RENDERER_AUTO_DETECT:
this.renderer = new Phaser.Renderer.Headless.HeadlessRenderer(this);
break;
case Phaser.Types.RENDERER_AUTO_DETECT:
case Phaser.Types.RENDERER_CANVAS:
this.renderer = new Phaser.Renderer.Canvas.CanvasRenderer(this);
break;
// WebGL coming soon :)
}
};
Game.prototype.loadComplete = /**
* Called when the load has finished after preload was run.
*/
@ -18673,6 +18698,18 @@ var Phaser;
this._loadComplete = true;
}
};
Game.prototype.setRenderer = function (type) {
switch(type) {
case Phaser.Types.RENDERER_AUTO_DETECT:
this.renderer = new Phaser.Renderer.Headless.HeadlessRenderer(this);
break;
case Phaser.Types.RENDERER_AUTO_DETECT:
case Phaser.Types.RENDERER_CANVAS:
this.renderer = new Phaser.Renderer.Canvas.CanvasRenderer(this);
break;
// WebGL coming soon :)
}
};
Game.prototype.setCallbacks = /**
* Set the most common state callbacks (init, create, update, render).
* @param preloadCallback {function} Init callback invoked when init state.
@ -18796,11 +18833,14 @@ var Phaser;
set: function (value) {
if(value == true && this._paused == false) {
this._paused = true;
this.onPause.dispatch();
// Hook to the above
this.sound.pauseAll();
this._raf.callback = this.pausedLoop;
} else if(value == false && this._paused == true) {
this._paused = false;
//this.time.time = window.performance.now ? (performance.now() + performance.timing.navigationStart) : Date.now();
this.onResume.dispatch();
// Hook to the above
this.input.reset();
this.sound.resumeAll();
if(this.isRunning == false) {

View file

@ -0,0 +1,14 @@
/// <reference path="../../Phaser/Game.ts" />
(function () {
var game = new Phaser.Game(this, 'game', 800, 600, preload, create);
function preload() {
game.load.image('atari', 'assets/sprites/atari130xe.png');
}
var atari;
function create() {
atari = game.add.sprite(300, 0, 'atari');
game.add.tween(atari).to({
y: 500
}, 5000, Phaser.Easing.Bounce.Out, true, 5000);
}
})();

View file

@ -0,0 +1,21 @@
/// <reference path="../../Phaser/Game.ts" />
(function () {
var game = new Phaser.Game(this, 'game', 800, 600, preload, create);
function preload() {
game.load.image('atari', 'assets/sprites/atari130xe.png');
}
var atari: Phaser.Sprite;
function create() {
atari = game.add.sprite(300, 0, 'atari');
game.add.tween(atari).to({ y: 500 }, 5000, Phaser.Easing.Bounce.Out, true, 5000);
}
})();

39
build/phaser.d.ts vendored
View file

@ -5439,6 +5439,9 @@ module Phaser {
* @return {Phaser.Tween} Itselfe.
*/
public chain(tween: Tween): Tween;
public pause(): void;
public resume(): void;
private _paused;
/**
* Update tweening.
* @param time {number} Current time from game clock.
@ -7366,12 +7369,6 @@ module Phaser {
*/
private _started;
/**
* Time scale factor.
* Set it to 0.5 for slow motion, to 2.0 makes game twice faster.
* @type {number}
*/
public timeScale: number;
/**
* Elapsed since last frame.
* @type {number}
*/
@ -7383,6 +7380,12 @@ module Phaser {
*/
public time: number;
/**
* How long the game has been paused for. Gets reset each time the game pauses.
* @property pausedTime
* @type {number}
*/
public pausedTime: number;
/**
* Time of current frame.
* @property now
* @type {number}
@ -7416,12 +7419,12 @@ module Phaser {
*/
public fpsMax: number;
/**
* Mininal duration between 2 frames.
* Minimum duration between 2 frames.
* @type {number}
*/
public msMin: number;
/**
* Maximal duration between 2 frames.
* Maximum duration between 2 frames.
* @type {number}
*/
public msMax: number;
@ -7442,6 +7445,10 @@ module Phaser {
* @param {number} raf The current timestamp, either performance.now or Date.now
*/
public update(raf: number): void;
private gamePaused();
private gameResumed();
public pauseDuration: number;
private _pauseStarted;
/**
* How long has passed since given time.
* @method elapsedSince
@ -7450,7 +7457,7 @@ module Phaser {
*/
public elapsedSince(since: number): number;
/**
* How long has passed since give time (in seconds).
* How long has passed since the given time (in seconds).
* @method elapsedSecondsSince
* @param {number} since The time you want to measure (in seconds).
* @return {number} Duration between given time and now (in seconds).
@ -7523,6 +7530,8 @@ module Phaser {
* @return {boolean} Return false if there's no tween to update, otherwise return true.
*/
public update(): bool;
public pauseAll(): bool;
public resumeAll(): bool;
}
}
/**
@ -9602,6 +9611,16 @@ module Phaser {
*/
public onDestroyCallback;
/**
* This Signal is dispatched whenever the game pauses.
* @type {Phaser.Signal}
*/
public onPause: Signal;
/**
* This Signal is dispatched whenever the game resumes from a paused state.
* @type {Phaser.Signal}
*/
public onResume: Signal;
/**
* Reference to the GameObject Factory.
* @type {GameObjectFactory}
*/
@ -9693,7 +9712,6 @@ module Phaser {
* @param height {number} Height of the game screen.
*/
private boot(parent, width, height);
public setRenderer(type: number): void;
/**
* Called when the load has finished after preload was run.
*/
@ -9715,6 +9733,7 @@ module Phaser {
* Start current state.
*/
private startState();
public setRenderer(type: number): void;
/**
* Set the most common state callbacks (init, create, update, render).
* @param preloadCallback {function} Init callback invoked when init state.

View file

@ -10693,24 +10693,20 @@ var Phaser;
this._chainedTweens.push(tween);
return this;
};
Tween.prototype.pause = function () {
this._paused = true;
};
Tween.prototype.resume = function () {
this._paused = false;
this._startTime += this.game.time.pauseDuration;
};
Tween.prototype.update = /**
* Update tweening.
* @param time {number} Current time from game clock.
* @return {boolean} Return false if this completed and no need to update, otherwise return true.
*/
function (time) {
if(this.game.paused == true) {
if(this._pausedTime == 0) {
this._pausedTime = time;
}
} else {
// Ok we aren't paused, but was there some time gained?
if(this._pausedTime > 0) {
this._startTime += (time - this._pausedTime);
this._pausedTime = 0;
}
}
if(time < this._startTime) {
if(this._paused || time < this._startTime) {
return true;
}
this._tempElapsed = (time - this._startTime) / this._duration;
@ -14192,11 +14188,11 @@ var Phaser;
this.canvas.style['-ms-interpolation-mode'] = 'nearest-neighbor';
};
Stage.prototype.pauseGame = function () {
this.game.paused = true;
if(this.disablePauseScreen == false && this.pauseScreen) {
this.pauseScreen.onPaused();
}
this.saveCanvasValues();
this.game.paused = true;
};
Stage.prototype.resumeGame = function () {
if(this.disablePauseScreen == false && this.pauseScreen) {
@ -14336,7 +14332,7 @@ var Phaser;
* Set it to 0.5 for slow motion, to 2.0 makes game twice faster.
* @type {number}
*/
this.timeScale = 1.0;
//public timeScale: number = 1.0;
/**
* Elapsed since last frame.
* @type {number}
@ -14349,6 +14345,12 @@ var Phaser;
*/
this.time = 0;
/**
* How long the game has been paused for. Gets reset each time the game pauses.
* @property pausedTime
* @type {number}
*/
this.pausedTime = 0;
/**
* Time of current frame.
* @property now
* @type {number}
@ -14376,12 +14378,12 @@ var Phaser;
*/
this.fpsMax = 0;
/**
* Mininal duration between 2 frames.
* Minimum duration between 2 frames.
* @type {number}
*/
this.msMin = 1000;
/**
* Maximal duration between 2 frames.
* Maximum duration between 2 frames.
* @type {number}
*/
this.msMax = 0;
@ -14395,10 +14397,14 @@ var Phaser;
* @type {number}
*/
this._timeLastSecond = 0;
this.pauseDuration = 0;
this._pauseStarted = 0;
this.game = game;
this._started = 0;
this._timeLastSecond = this._started;
this.time = this._started;
this.game.onPause.add(this.gamePaused, this);
this.game.onResume.add(this.gameResumed, this);
}
Object.defineProperty(TimeManager.prototype, "totalElapsedSeconds", {
get: /**
@ -14421,7 +14427,6 @@ var Phaser;
function (raf) {
this.now = raf// mark
;
//this.now = Date.now(); // mark
this.delta = this.now - this.time// elapsedMS
;
this.msMin = Math.min(this.msMin, this.delta);
@ -14436,6 +14441,17 @@ var Phaser;
}
this.time = this.now// _total
;
// Paused?
if(this.game.paused) {
this.pausedTime = this.now - this._pauseStarted;
}
};
TimeManager.prototype.gamePaused = function () {
this._pauseStarted = this.now;
};
TimeManager.prototype.gameResumed = function () {
// Level out the delta timer to avoid spikes
this.pauseDuration = this.pausedTime;
};
TimeManager.prototype.elapsedSince = /**
* How long has passed since given time.
@ -14447,7 +14463,7 @@ var Phaser;
return this.now - since;
};
TimeManager.prototype.elapsedSecondsSince = /**
* How long has passed since give time (in seconds).
* How long has passed since the given time (in seconds).
* @method elapsedSecondsSince
* @param {number} since The time you want to measure (in seconds).
* @return {number} Duration between given time and now (in seconds).
@ -14487,6 +14503,8 @@ var Phaser;
function TweenManager(game) {
this.game = game;
this._tweens = [];
this.game.onPause.add(this.pauseAll, this);
this.game.onResume.add(this.resumeAll, this);
}
TweenManager.prototype.getAll = /**
* Get all the tween objects in an array.
@ -14560,6 +14578,28 @@ var Phaser;
}
return true;
};
TweenManager.prototype.pauseAll = function () {
if(this._tweens.length === 0) {
return false;
}
var i = 0;
var numTweens = this._tweens.length;
while(i < numTweens) {
this._tweens[i].pause();
i++;
}
};
TweenManager.prototype.resumeAll = function () {
if(this._tweens.length === 0) {
return false;
}
var i = 0;
var numTweens = this._tweens.length;
while(i < numTweens) {
this._tweens[i].resume();
i++;
}
};
return TweenManager;
})();
Phaser.TweenManager = TweenManager;
@ -18419,11 +18459,6 @@ var Phaser;
if (typeof destroyCallback === "undefined") { destroyCallback = null; }
var _this = this;
/**
* Milliseconds of time per step of the game loop.
* @type {number}
*/
//private _step: number = 0;
/**
* Whether load complete loading or not.
* @type {boolean}
*/
@ -18532,6 +18567,8 @@ var Phaser;
} else {
document.removeEventListener('DOMContentLoaded', Phaser.GAMES[this.id].boot);
window.removeEventListener('load', Phaser.GAMES[this.id].boot);
this.onPause = new Phaser.Signal();
this.onResume = new Phaser.Signal();
this.device = new Phaser.Device();
this.net = new Phaser.Net(this);
this.math = new Phaser.GameMath(this);
@ -18574,18 +18611,6 @@ var Phaser;
}
}
};
Game.prototype.setRenderer = function (type) {
switch(type) {
case Phaser.Types.RENDERER_AUTO_DETECT:
this.renderer = new Phaser.Renderer.Headless.HeadlessRenderer(this);
break;
case Phaser.Types.RENDERER_AUTO_DETECT:
case Phaser.Types.RENDERER_CANVAS:
this.renderer = new Phaser.Renderer.Canvas.CanvasRenderer(this);
break;
// WebGL coming soon :)
}
};
Game.prototype.loadComplete = /**
* Called when the load has finished after preload was run.
*/
@ -18673,6 +18698,18 @@ var Phaser;
this._loadComplete = true;
}
};
Game.prototype.setRenderer = function (type) {
switch(type) {
case Phaser.Types.RENDERER_AUTO_DETECT:
this.renderer = new Phaser.Renderer.Headless.HeadlessRenderer(this);
break;
case Phaser.Types.RENDERER_AUTO_DETECT:
case Phaser.Types.RENDERER_CANVAS:
this.renderer = new Phaser.Renderer.Canvas.CanvasRenderer(this);
break;
// WebGL coming soon :)
}
};
Game.prototype.setCallbacks = /**
* Set the most common state callbacks (init, create, update, render).
* @param preloadCallback {function} Init callback invoked when init state.
@ -18796,11 +18833,14 @@ var Phaser;
set: function (value) {
if(value == true && this._paused == false) {
this._paused = true;
this.onPause.dispatch();
// Hook to the above
this.sound.pauseAll();
this._raf.callback = this.pausedLoop;
} else if(value == false && this._paused == true) {
this._paused = false;
//this.time.time = window.performance.now ? (performance.now() + performance.timing.navigationStart) : Date.now();
this.onResume.dispatch();
// Hook to the above
this.input.reset();
this.sound.resumeAll();
if(this.isRunning == false) {