From a61d0302563fe4c6b64274e6765ae5cd62cd5085 Mon Sep 17 00:00:00 2001 From: photonstorm Date: Fri, 21 Feb 2014 13:25:08 +0000 Subject: [PATCH] Display Objects now clean-up their children properly on destroy. --- src/gameobjects/BitmapText.js | 23 +++++++++-------------- src/gameobjects/Image.js | 7 +++++++ src/gameobjects/Sprite.js | 8 ++++++++ src/gameobjects/Text.js | 16 ++++++++++------ src/gameobjects/TileSprite.js | 9 +++++++++ 5 files changed, 43 insertions(+), 20 deletions(-) diff --git a/src/gameobjects/BitmapText.js b/src/gameobjects/BitmapText.js index 12dcc238..c2b86bde 100644 --- a/src/gameobjects/BitmapText.js +++ b/src/gameobjects/BitmapText.js @@ -204,30 +204,25 @@ Phaser.BitmapText.prototype.postUpdate = function () { */ Phaser.BitmapText.prototype.destroy = function() { - if (this.filters) - { - this.filters = null; - } - if (this.parent) { this.parent.remove(this); } + var i = this.children.length; + + while (i--) + { + this.removeChild(this.children[i]); + } + this.exists = false; this.visible = false; + this.filters = null; + this.mask = null; this.game = null; - if (this.children.length > 0) - { - do - { - this.removeChild(this.children[0]); - } - while (this.children.length > 0); - } - } /** diff --git a/src/gameobjects/Image.js b/src/gameobjects/Image.js index 2e6d7ee4..a76285b6 100644 --- a/src/gameobjects/Image.js +++ b/src/gameobjects/Image.js @@ -384,6 +384,13 @@ Phaser.Image.prototype.destroy = function() { this.input.destroy(); } + var i = this.children.length; + + while (i--) + { + this.removeChild(this.children[i]); + } + this.alive = false; this.exists = false; this.visible = false; diff --git a/src/gameobjects/Sprite.js b/src/gameobjects/Sprite.js index 9e260810..04769f33 100644 --- a/src/gameobjects/Sprite.js +++ b/src/gameobjects/Sprite.js @@ -14,6 +14,7 @@ * events (via Sprite.events), animation (via Sprite.animations), camera culling and more. Please see the Examples for use cases. * * @constructor +* @extends PIXI.Sprite * @param {Phaser.Game} game - A reference to the currently running game. * @param {number} x - The x coordinate (in world space) to position the Sprite at. * @param {number} y - The y coordinate (in world space) to position the Sprite at. @@ -516,6 +517,13 @@ Phaser.Sprite.prototype.destroy = function() { this.events.destroy(); } + var i = this.children.length; + + while (i--) + { + this.removeChild(this.children[i]); + } + this.alive = false; this.exists = false; this.visible = false; diff --git a/src/gameobjects/Text.js b/src/gameobjects/Text.js index 5aa0b423..2bca231f 100644 --- a/src/gameobjects/Text.js +++ b/src/gameobjects/Text.js @@ -10,6 +10,7 @@ * Here is a compatibility table showing the available default fonts across different mobile browsers: http://www.jordanm.co.uk/tinytype * * @class Phaser.Text +* @extends PIXI.Text * @constructor * @param {Phaser.Game} game - Current game instance. * @param {number} x - X position of the new text object. @@ -170,7 +171,6 @@ Phaser.Text.prototype.update = function() { */ Phaser.Text.prototype.postUpdate = function () { - // Fixed to Camera? if (this._cache[7] === 1) { this.position.x = this.game.camera.view.x + this.cameraOffset.x; @@ -184,11 +184,6 @@ Phaser.Text.prototype.postUpdate = function () { */ Phaser.Text.prototype.destroy = function () { - if (this.filters) - { - this.filters = null; - } - if (this.parent) { this.parent.remove(this); @@ -206,9 +201,18 @@ Phaser.Text.prototype.destroy = function () { this.context = null; } + var i = this.children.length; + + while (i--) + { + this.removeChild(this.children[i]); + } + this.exists = false; this.visible = false; + this.filters = null; + this.mask = null; this.game = null; } diff --git a/src/gameobjects/TileSprite.js b/src/gameobjects/TileSprite.js index e147145f..e44d0962 100644 --- a/src/gameobjects/TileSprite.js +++ b/src/gameobjects/TileSprite.js @@ -288,9 +288,18 @@ Phaser.TileSprite.prototype.destroy = function() { this.events.destroy(); + var i = this.children.length; + + while (i--) + { + this.removeChild(this.children[i]); + } + this.exists = false; this.visible = false; + this.filters = null; + this.mask = null; this.game = null; }