Skip to content

Commit 3e1207e

Browse files
committed
Split world update into preUpdate and update.
This allows moving the state.update() call to before world.update(), meaning results of collisions checked in the state are available to objects in their own update().
1 parent 74e0cfb commit 3e1207e

2 files changed

Lines changed: 33 additions & 19 deletions

File tree

src/core/Game.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,14 +440,15 @@ Phaser.Game.prototype = {
440440
{
441441
this.plugins.preUpdate();
442442
this.physics.preUpdate();
443+
this.world.preUpdate();
443444

444445
this.stage.update();
445446
this.input.update();
446447
this.tweens.update();
447448
this.sound.update();
448-
this.world.update();
449-
this.particles.update();
450449
this.state.update();
450+
this.world.update();
451+
this.particles.update();
451452
this.plugins.update();
452453

453454
this.world.postUpdate();

src/core/World.js

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,35 +65,48 @@ Phaser.World.prototype.boot = function () {
6565
*
6666
* @method Phaser.World#update
6767
*/
68-
Phaser.World.prototype.update = function () {
69-
70-
this.currentRenderOrderID = 0;
68+
Phaser.World.prototype.preUpdate = function () {
7169

7270
if (this.game.stage._stage.first._iNext)
7371
{
7472
var currentNode = this.game.stage._stage.first._iNext;
75-
var skipChildren;
7673

7774
do
7875
{
79-
skipChildren = false;
80-
81-
if (currentNode['preUpdate'])
76+
// If preUpdate exists, and it returns false, skip PIXI child objects
77+
if (currentNode['preUpdate'] && !currentNode.preUpdate())
8278
{
83-
skipChildren = (currentNode.preUpdate() === false);
84-
}
85-
86-
if (currentNode['update'])
87-
{
88-
skipChildren = (currentNode.update() === false) || skipChildren;
79+
currentNode = currentNode.last._iNext;
80+
} else {
81+
currentNode = currentNode._iNext;
8982
}
9083

91-
if (skipChildren)
84+
}
85+
while (currentNode != this.game.stage._stage.last._iNext)
86+
}
87+
88+
}
89+
90+
/**
91+
* This is called automatically every frame, and is where main logic happens.
92+
*
93+
* @method Phaser.World#update
94+
*/
95+
Phaser.World.prototype.update = function () {
96+
97+
this.currentRenderOrderID = 0;
98+
99+
if (this.game.stage._stage.first._iNext)
100+
{
101+
var currentNode = this.game.stage._stage.first._iNext;
102+
103+
do
104+
{
105+
// If update exists, and it returns false, skip PIXI child objects
106+
if (currentNode['update'] && !currentNode.update())
92107
{
93108
currentNode = currentNode.last._iNext;
94-
}
95-
else
96-
{
109+
} else {
97110
currentNode = currentNode._iNext;
98111
}
99112

0 commit comments

Comments
 (0)