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

This commit is contained in:
photonstorm 2014-02-14 17:29:31 +00:00
parent bcd31499c4
commit 1b5837d71d
4 changed files with 75 additions and 68 deletions

View file

@ -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:

View file

@ -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();
}

View file

@ -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.
*

View file

@ -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.
*