Buttons are now cleanly destroyed if part of a Group without leaving their InputHandler running.

You can now safely destroy a Group and the 'destroyChildren' boolean will propogate fully down the display list.
Calling destroy on an already destroyed object would throw a run-time error. Now checked for and aborted.
Calling destroy while in an Input Event callback now works for either the parent Group or the calling object itself.
In Group.destroy the default for 'destroyChildren' was false. It's now `true` as this is a far more likely requirement when destroying a Group.
All GameObjects now have a 'destroyChildren' boolean as a parameter to their destroy method. It's default is true and the value propogates down its children.
This commit is contained in:
photonstorm
2014-02-27 20:05:16 +00:00
parent 53c10ca31f
commit 7e12075be1
9 changed files with 201 additions and 20 deletions
+25 -3
View File
@@ -201,8 +201,13 @@ Phaser.BitmapText.prototype.postUpdate = function () {
/**
* Destroy this BitmapText instance. This will remove any filters and un-parent any children.
* @method Phaser.BitmapText.prototype.destroy
* @param {boolean} [destroyChildren=true] - Should every child of this object have its destroy method called?
*/
Phaser.BitmapText.prototype.destroy = function() {
Phaser.BitmapText.prototype.destroy = function(destroyChildren) {
if (this.game === null) { return; }
if (typeof destroyChildren === 'undefined') { destroyChildren = true; }
if (this.parent)
{
@@ -211,9 +216,26 @@ Phaser.BitmapText.prototype.destroy = function() {
var i = this.children.length;
while (i--)
if (destroyChildren)
{
this.removeChild(this.children[i]);
while (i--)
{
if (this.children[i].destroy)
{
this.children[i].destroy(destroyChildren);
}
else
{
this.removeChild(this.children[i]);
}
}
}
else
{
while (i--)
{
this.removeChild(this.children[i]);
}
}
this.exists = false;