Skip to content

Commit 84c60d4

Browse files
committed
Within RequestAnimationFrame both updateRAF and updateSetTimeout now only call game.update if isRunning is true. This should avoid asynchronous Game destroy errors under environments like Angular (thanks @flogvit phaserjs#2521)
1 parent 05ca827 commit 84c60d4

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/
343343
* Animation.reverseOnce will reverse the animation direction for the current, or next animation only (thanks @gotenxds #2505)
344344
* The way the display list updates and Camera movements are handled has been completely revamped, which should result is significantly smoother motion when the Camera is following tweened or physics controlled sprites. The `Stage.postUpdate` function is now vastly reduced in complexity. It takes control over updating the display list (calling `updateTransform` on itself), rather than letting the Canvas or WebGL renderers do this. Because of this change, the `Camera.updateTarget` function uses the Sprites `worldPosition` property instead, which is now frame accurate (thanks @whig @Upperfoot @Whoisnt @hexus #2482)
345345
* Game Objects including Sprite, Image, Particle, TilemapLayer, Text, BitmapText and TileSprite have a new property called `data`. This is an empty Object that Phaser will never touch internally, but your own code, or Phaser Plugins, can store Game Object specific data within it. This allows you to associate data with a Game Object without having to pollute or change its class shape.
346+
* TilemapLayers will now collide properly when they have a position that isn't set to 0x0. For example if you're stitching together several maps, one after the other, and manually adjust their `scrollX/Y` properties (thanks @Upperfoot #2522)
346347

347348
### Updates
348349

@@ -356,6 +357,7 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/
356357
* Removed the `Stage.updateTransform` calls from the main game loop, because it happens automatically as part of `Game.updateLogic` anyway, so was duplicating the workload for no reason.
357358
* TilemapLayer.postUpdate could potentially be called several times per frame (depending on device frame rate), which would cause multiple texture redraws, even though only the last texture is used during rendering. This has now been modified so that the local TilemapLayer canvas is only re-rendered once per frame, during the rendering phase, and not during the logic update phase.
358359
* Stage has had all of its core update loops modified, so they now iterate through the display list forwards, instead of in reverse. Stage.postUpdate is now also a lot smaller, with no conditional branching if there is a Camera Target or not.
360+
* Within RequestAnimationFrame both `updateRAF` and `updateSetTimeout` now only call `game.update` if `isRunning` is true. This should avoid asynchronous Game destroy errors under environments like Angular (thanks @flogvit #2521)
359361

360362
### Bug Fixes
361363

src/system/RequestAnimationFrame.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,16 @@ Phaser.RequestAnimationFrame.prototype = {
103103
/**
104104
* The update method for the requestAnimationFrame
105105
* @method Phaser.RequestAnimationFrame#updateRAF
106-
*
107106
*/
108107
updateRAF: function (rafTime) {
109108

110-
// floor the rafTime to make it equivalent to the Date.now() provided by updateSetTimeout (just below)
111-
this.game.update(Math.floor(rafTime));
109+
if (this.isRunning)
110+
{
111+
// floor the rafTime to make it equivalent to the Date.now() provided by updateSetTimeout (just below)
112+
this.game.update(Math.floor(rafTime));
112113

113-
this._timeOutID = window.requestAnimationFrame(this._onLoop);
114+
this._timeOutID = window.requestAnimationFrame(this._onLoop);
115+
}
114116

115117
},
116118

@@ -120,9 +122,12 @@ Phaser.RequestAnimationFrame.prototype = {
120122
*/
121123
updateSetTimeout: function () {
122124

123-
this.game.update(Date.now());
125+
if (this.isRunning)
126+
{
127+
this.game.update(Date.now());
124128

125-
this._timeOutID = window.setTimeout(this._onLoop, this.game.time.timeToCall);
129+
this._timeOutID = window.setTimeout(this._onLoop, this.game.time.timeToCall);
130+
}
126131

127132
},
128133

0 commit comments

Comments
 (0)