diff --git a/src/core/Group.js b/src/core/Group.js index b4f4dca72..74bb21dcf 100644 --- a/src/core/Group.js +++ b/src/core/Group.js @@ -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(); } } diff --git a/src/core/World.js b/src/core/World.js index a550b1dfe..4647d11cb 100644 --- a/src/core/World.js +++ b/src/core/World.js @@ -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(); } } diff --git a/src/gameobjects/Image.js b/src/gameobjects/Image.js index a56907540..d53cc3df3 100644 --- a/src/gameobjects/Image.js +++ b/src/gameobjects/Image.js @@ -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. diff --git a/src/gameobjects/Sprite.js b/src/gameobjects/Sprite.js index e329aadb4..b13634a1c 100644 --- a/src/gameobjects/Sprite.js +++ b/src/gameobjects/Sprite.js @@ -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. * diff --git a/src/gameobjects/Text.js b/src/gameobjects/Text.js index ad1b69280..b89281fab 100644 --- a/src/gameobjects/Text.js +++ b/src/gameobjects/Text.js @@ -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. diff --git a/src/gameobjects/TileSprite.js b/src/gameobjects/TileSprite.js index 0738d8076..644047d26 100644 --- a/src/gameobjects/TileSprite.js +++ b/src/gameobjects/TileSprite.js @@ -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.