Merge pull request #254 from cocoademon/update_reorder

Split world update into preUpdate and update.
This commit is contained in:
Richard Davey
2013-12-09 02:00:49 -08:00
2 changed files with 33 additions and 19 deletions
+3 -2
View File
@@ -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();
+30 -17
View File
@@ -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;
}