From 1b5837d71d0bd86395ddd9096f1efe711fe5ce1a Mon Sep 17 00:00:00 2001 From: photonstorm Date: Fri, 14 Feb 2014 17:29:31 +0000 Subject: [PATCH] World preUpdate, update and postUpdate have all been moved to Stage. So all children are updated regardless where on the display list they live. Fixes #419 --- README.md | 1 + src/core/Game.js | 5 ++-- src/core/Stage.js | 72 +++++++++++++++++++++++++++++++++++++++++++++++ src/core/World.js | 65 ------------------------------------------ 4 files changed, 75 insertions(+), 68 deletions(-) diff --git a/README.md b/README.md index 92c5e209d..b49220ad8 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,7 @@ Significant API changes: * BitmapData.addTo removed and enhanced BitmapData.add so it can accept either a single Sprite/Image or an Array of them. * BitmapData has had all of the EaselJS functions removed. It was just taking up space and you can do it all via BitmapData.context directly. * BitmapText has had a bit of an overhaul - the signature for adding a BitmapText has changed to: x, y, font, text, size. See the docs and examples for details. +* World preUpdate, update and postUpdate have all been moved to Stage. So all children are updated regardless where on the display list they live. New features: diff --git a/src/core/Game.js b/src/core/Game.js index f391a8df3..2873fefc6 100644 --- a/src/core/Game.js +++ b/src/core/Game.js @@ -600,7 +600,7 @@ Phaser.Game.prototype = { } this.plugins.preUpdate(); - this.world.preUpdate(); + this.stage.preUpdate(); this.stage.update(); this.tweens.update(); @@ -610,9 +610,8 @@ Phaser.Game.prototype = { this.physics.update(); this.particles.update(); this.plugins.update(); - this.world.update(); - this.world.postUpdate(); + this.stage.postUpdate(); this.plugins.postUpdate(); } diff --git a/src/core/Stage.js b/src/core/Stage.js index c16feda15..1f2d62af6 100644 --- a/src/core/Stage.js +++ b/src/core/Stage.js @@ -70,6 +70,78 @@ Phaser.Stage = function (game, width, height) { Phaser.Stage.prototype = Object.create(PIXI.Stage.prototype); Phaser.Stage.prototype.constructor = Phaser.Stage; +/** +* This is called automatically after the plugins preUpdate and before the State.update. +* Most objects have preUpdate methods and it's where initial movement and positioning is done. +* +* @method Phaser.Stage#preUpdate +*/ +Phaser.Stage.prototype.preUpdate = function () { + + this.currentRenderOrderID = 0; + + var i = this.children.length; + + while(i--) + { + this.children[i].preUpdate(); + } + +} + +/** +* This is called automatically after the State.update, but before particles or plugins update. +* +* @method Phaser.Stage#update +*/ +Phaser.Stage.prototype.update = function () { + + var i = this.children.length; + + while(i--) + { + this.children[i].update(); + } + +} + +/** +* This is called automatically before the renderer runs and after the plugins have updated. +* In postUpdate this is where all the final physics calculatations and object positioning happens. +* The objects are processed in the order of the display list. +* The only exception to this is if the camera is following an object, in which case that is updated first. +* +* @method Phaser.Stage#postUpdate +*/ +Phaser.Stage.prototype.postUpdate = function () { + + if (this.game.world.camera.target) + { + this.game.world.camera.target.postUpdate(); + + this.game.world.camera.update(); + + var i = this.children.length; + + while(i-- && this.children[i] !== this.game.world.camera.target) + { + this.children[i].postUpdate(); + } + } + else + { + this.game.world.camera.update(); + + var i = this.children.length; + + while(i--) + { + this.children[i].postUpdate(); + } + } + +} + /** * Parses a Game configuration object. * diff --git a/src/core/World.js b/src/core/World.js index 4647d11cb..421e44f83 100644 --- a/src/core/World.js +++ b/src/core/World.js @@ -62,71 +62,6 @@ Phaser.World.prototype.boot = function () { } -/** -* This is called automatically after the plugins preUpdate and before the State.update. -* Most objects have preUpdate methods and it's where initial movement and positioning is done. -* -* @method Phaser.World#preUpdate -*/ -Phaser.World.prototype.preUpdate = function () { - - this.currentRenderOrderID = 0; - - for (var i = this.children.length - 1; i >= 0; i--) - { - this.children[i].preUpdate(); - } - -} - -/** -* This is called automatically after the State.update, but before particles or plugins update. -* Most objects won't have an update method set unless explicitly given one. -* -* @method Phaser.World#update -*/ -Phaser.World.prototype.update = function () { - - for (var i = this.children.length - 1; i >= 0; i--) - { - this.children[i].update(); - } - -} - -/** -* This is called automatically before the renderer runs and after the plugins have updated. -* In postUpdate this is where all the final physics calculatations and object positioning happens. -* The objects are processed in the order of the display list. -* The only exception to this is if the camera is following an object, in which case that is updated first. -* -* @method Phaser.World#postUpdate -*/ -Phaser.World.prototype.postUpdate = function () { - - if (this.camera.target && this.camera.target['postUpdate']) - { - this.camera.target.postUpdate(); - - this.camera.update(); - - for (var i = this.children.length - 1; i >= 0; i--) - { - this.children[i].postUpdate(); - } - } - else - { - this.camera.update(); - - for (var i = this.children.length - 1; i >= 0; i--) - { - this.children[i].postUpdate(); - } - } - -} - /** * Updates the size of this world. Note that this doesn't modify the world x/y coordinates, just the width and height. *