Updated all Game Objects so they all have preUpdate, update and postUpdate functions (even if empty). Updated World so when it iterates through them all it no longer checks if those functions are present before calling them. Was wasting a lot of time doing that before.

This commit is contained in:
photonstorm
2014-02-14 01:09:52 +00:00
parent f9a4beb608
commit 3e99391cbf
6 changed files with 74 additions and 55 deletions
+8 -17
View File
@@ -7,10 +7,10 @@
/**
* Phaser Group constructor.
* @class Phaser.Group
* @classdesc A Group is a container for display objects that allows for fast pooling, recycling and collision checks.
* @classdesc A Group is a container for display objects that allows for fast pooling and object recycling. Groups can be nested within other Groups and have their own local transforms.
* @constructor
* @param {Phaser.Game} game - A reference to the currently running game.
* @param {*} parent - The parent Group, DisplayObject or DisplayObjectContainer that this Group will be added to. If undefined or null it will use game.world.
* @param {Phaser.Group|Phaser.Sprite} parent - The parent Group, DisplayObject or DisplayObjectContainer that this Group will be added to. If undefined or null it will use game.world.
* @param {string} [name=group] - A name for this Group. Not used internally but useful for debugging.
* @param {boolean} [addToStage=false] - If set to true this Group will be added directly to the Game.Stage instead of Game.World.
*/
@@ -708,12 +708,9 @@ Phaser.Group.prototype.callAll = function (method, context) {
*/
Phaser.Group.prototype.preUpdate = function () {
for (var i = 0, len = this.children.length; i < len; i++)
for (var i = this.children.length - 1; i >= 0; i--)
{
if (this.children[i]['preUpdate'])
{
this.children[i].preUpdate();
}
this.children[i].preUpdate();
}
}
@@ -725,12 +722,9 @@ Phaser.Group.prototype.preUpdate = function () {
*/
Phaser.Group.prototype.update = function () {
for (var i = 0, len = this.children.length; i < len; i++)
for (var i = this.children.length - 1; i >= 0; i--)
{
if (this.children[i]['update'])
{
this.children[i].update();
}
this.children[i].update();
}
}
@@ -742,12 +736,9 @@ Phaser.Group.prototype.update = function () {
*/
Phaser.Group.prototype.postUpdate = function () {
for (var i = 0, len = this.children.length; i < len; i++)
for (var i = this.children.length - 1; i >= 0; i--)
{
if (this.children[i]['postUpdate'])
{
this.children[i].postUpdate();
}
this.children[i].postUpdate();
}
}
+9 -21
View File
@@ -39,7 +39,7 @@ Phaser.World = function (game) {
*/
this.currentRenderOrderID = 0;
};
}
Phaser.World.prototype = Object.create(Phaser.Group.prototype);
Phaser.World.prototype.constructor = Phaser.World;
@@ -72,12 +72,9 @@ Phaser.World.prototype.preUpdate = function () {
this.currentRenderOrderID = 0;
for (var i = 0, len = this.children.length; i < len; i++)
for (var i = this.children.length - 1; i >= 0; i--)
{
if (this.children[i]['preUpdate'])
{
this.children[i].preUpdate();
}
this.children[i].preUpdate();
}
}
@@ -90,12 +87,9 @@ Phaser.World.prototype.preUpdate = function () {
*/
Phaser.World.prototype.update = function () {
for (var i = 0, len = this.children.length; i < len; i++)
for (var i = this.children.length - 1; i >= 0; i--)
{
if (this.children[i]['update'])
{
this.children[i].update();
}
this.children[i].update();
}
}
@@ -116,24 +110,18 @@ Phaser.World.prototype.postUpdate = function () {
this.camera.update();
for (var i = 0, len = this.children.length; i < len; i++)
for (var i = this.children.length - 1; i >= 0; i--)
{
if (this.children[i]['postUpdate'])
{
this.children[i].postUpdate();
}
this.children[i].postUpdate();
}
}
else
{
this.camera.update();
for (var i = 0, len = this.children.length; i < len; i++)
for (var i = this.children.length - 1; i >= 0; i--)
{
if (this.children[i]['postUpdate'])
{
this.children[i].postUpdate();
}
this.children[i].postUpdate();
}
}