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

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

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

View file

@ -147,7 +147,17 @@ Phaser.Image.prototype.preUpdate = function() {
return true;
};
}
/**
* Override and use this function in your own custom objects to handle any update requirements you may have.
*
* @method Phaser.Image#update
* @memberof Phaser.Image
*/
Phaser.Image.prototype.update = function() {
}
/**
* Internal function called by the World postUpdate cycle.
@ -168,7 +178,7 @@ Phaser.Image.prototype.postUpdate = function() {
this.position.y = this.game.camera.view.y + this.y;
}
};
}
/**
* Changes the Texture the Sprite is using entirely. The old texture is removed and the new one is referenced or fetched from the Cache.
@ -245,7 +255,7 @@ Phaser.Image.prototype.loadTexture = function (key, frame) {
}
}
};
}
/**
* Crop allows you to crop the texture used to display this Image.
@ -292,7 +302,7 @@ Phaser.Image.prototype.crop = function(rect) {
}
}
};
}
/**
* Brings a 'dead' Sprite back to life, optionally giving it the health value specified.
@ -316,7 +326,7 @@ Phaser.Image.prototype.revive = function() {
return this;
};
}
/**
* Kills a Sprite. A killed Sprite has its alive, exists and visible properties all set to false.
@ -341,7 +351,7 @@ Phaser.Image.prototype.kill = function() {
return this;
};
}
/**
* Destroys the Sprite. This removes it from its parent group, destroys the input, event and animation handlers if present
@ -378,7 +388,7 @@ Phaser.Image.prototype.destroy = function() {
this.game = null;
};
}
/**
* Resets the Sprite. This places the Sprite at the given x/y world coordinates and then sets alive, exists, visible and renderable all to true.
@ -401,7 +411,7 @@ Phaser.Image.prototype.reset = function(x, y) {
return this;
};
}
/**
* Brings the Sprite to the top of the display list it is a child of. Sprites that are members of a Phaser.Group are only
@ -427,7 +437,7 @@ Phaser.Image.prototype.bringToTop = function(child) {
return this;
};
}
/**
* Indicates the rotation of the Sprite, in degrees, from its original orientation. Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation.

View file

@ -153,10 +153,10 @@ Phaser.Sprite = function (game, x, y, key, frame) {
* 4 = fresh? (0 = no, 1 = yes)
* 5 = outOfBoundsFired (0 = no, 1 = yes)
* 6 = exists (0 = no, 1 = yes)
* @property {array} _cache
* @property {Int16Array} _cache
* @private
*/
this._cache = [0, 0, 0, 0, 1, 0, 1];
this._cache = new Int16Array([0, 0, 0, 0, 1, 0, 1]);
/**
* @property {Phaser.Rectangle} _bounds - Internal cache var.
@ -272,6 +272,16 @@ Phaser.Sprite.prototype.preUpdate = function() {
};
/**
* Override and use this function in your own custom objects to handle any update requirements you may have.
*
* @method Phaser.Sprite#update
* @memberof Phaser.Sprite
*/
Phaser.Sprite.prototype.update = function() {
};
/**
* Internal function called by the World postUpdate cycle.
*

View file

@ -121,6 +121,16 @@ Phaser.Text.prototype.preUpdate = function () {
}
/**
* Override and use this function in your own custom objects to handle any update requirements you may have.
*
* @method Phaser.Text#update
* @memberof Phaser.Text
*/
Phaser.Text.prototype.update = function() {
}
/**
* Automatically called by World.postUpdate.
* @method Phaser.Text.prototype.postUpdate
@ -219,7 +229,7 @@ Phaser.Text.prototype.setStyle = function (style) {
this.style = style;
this.dirty = true;
};
}
/**
* Renders text. This replaces the Pixi.Text.updateText function as we need a few extra bits in here.
@ -299,7 +309,7 @@ Phaser.Text.prototype.updateText = function () {
}
this.updateTexture();
};
}
/**
* Greedy wrapping algorithm that will wrap words as the line grows longer than its horizontal bounds.
@ -347,7 +357,7 @@ Phaser.Text.prototype.runWordWrap = function (text) {
return result;
};
}
/**
* Indicates the rotation of the Text, in degrees, from its original orientation. Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation.

View file

@ -119,6 +119,16 @@ Phaser.TileSprite.prototype.preUpdate = function() {
}
/**
* Override and use this function in your own custom objects to handle any update requirements you may have.
*
* @method Phaser.TileSprite#update
* @memberof Phaser.TileSprite
*/
Phaser.TileSprite.prototype.update = function() {
}
/**
* Internal function called by the World postUpdate cycle.
*
@ -232,7 +242,7 @@ Phaser.TileSprite.prototype.loadTexture = function (key, frame) {
}
}
};
}
/**
* Destroys the TileSprite. This removes it from its parent group, destroys the event and animation handlers if present
@ -262,7 +272,7 @@ Phaser.TileSprite.prototype.destroy = function() {
this.game = null;
};
}
/**
* Play an animation based on the given key. The animation should previously have been added via sprite.animations.add()
@ -280,7 +290,7 @@ Phaser.TileSprite.prototype.play = function (name, frameRate, loop, killOnComple
return this.animations.play(name, frameRate, loop, killOnComplete);
};
}
/**
* Indicates the rotation of the Sprite, in degrees, from its original orientation. Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation.