From 3e1207e1a3d15cb91aca55ac71d8bc5ba2c94c35 Mon Sep 17 00:00:00 2001 From: Cameron Foale Date: Mon, 9 Dec 2013 15:46:02 +1100 Subject: [PATCH] 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(). --- src/core/Game.js | 5 +++-- src/core/World.js | 47 ++++++++++++++++++++++++++++++----------------- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/core/Game.js b/src/core/Game.js index d077209e..692f6387 100644 --- a/src/core/Game.js +++ b/src/core/Game.js @@ -440,14 +440,15 @@ Phaser.Game.prototype = { { this.plugins.preUpdate(); this.physics.preUpdate(); + this.world.preUpdate(); this.stage.update(); this.input.update(); this.tweens.update(); this.sound.update(); - this.world.update(); - this.particles.update(); this.state.update(); + this.world.update(); + this.particles.update(); this.plugins.update(); this.world.postUpdate(); diff --git a/src/core/World.js b/src/core/World.js index 8ad6e8c7..9492b956 100644 --- a/src/core/World.js +++ b/src/core/World.js @@ -60,6 +60,33 @@ Phaser.World.prototype.boot = function () { } +/** +* This is called automatically every frame, and is where main logic happens. +* +* @method Phaser.World#update +*/ +Phaser.World.prototype.preUpdate = function () { + + if (this.game.stage._stage.first._iNext) + { + var currentNode = this.game.stage._stage.first._iNext; + + do + { + // If preUpdate exists, and it returns false, skip PIXI child objects + if (currentNode['preUpdate'] && !currentNode.preUpdate()) + { + currentNode = currentNode.last._iNext; + } else { + currentNode = currentNode._iNext; + } + + } + while (currentNode != this.game.stage._stage.last._iNext) + } + +} + /** * This is called automatically every frame, and is where main logic happens. * @@ -72,28 +99,14 @@ Phaser.World.prototype.update = function () { if (this.game.stage._stage.first._iNext) { var currentNode = this.game.stage._stage.first._iNext; - var skipChildren; do { - skipChildren = false; - - if (currentNode['preUpdate']) - { - skipChildren = (currentNode.preUpdate() === false); - } - - if (currentNode['update']) - { - skipChildren = (currentNode.update() === false) || skipChildren; - } - - if (skipChildren) + // If update exists, and it returns false, skip PIXI child objects + if (currentNode['update'] && !currentNode.update()) { currentNode = currentNode.last._iNext; - } - else - { + } else { currentNode = currentNode._iNext; }