Fixed the use of the destroy parameter in Group.removeAll and related functions (thanks @AnderbergE, fix #717)

This commit is contained in:
photonstorm 2014-04-14 12:57:29 +01:00
parent 2fd704062d
commit f70e4d7d90
2 changed files with 12 additions and 27 deletions

View file

@ -72,6 +72,8 @@ Version 2.0.4 - "Mos Shirare" - in development
### Bug Fixes
* The main Timer loop could incorrectly remove TimeEvent if a new one was added specifically during an event callback (thanks @garyyeap, fix #710)
* Fixed the use of the destroy parameter in Group.removeAll and related functions (thanks @AnderbergE, fix #717)
There is an extensive [Migration Guide](https://github.com/photonstorm/phaser/blob/master/resources/Migration%20Guide.md) available for those converting from Phaser 1.x to 2.x. In the guide we detail the API breaking changes and approach to our new physics system.

View file

@ -1411,7 +1411,7 @@ Phaser.Group.prototype.remove = function (child, destroy) {
child.events.onRemovedFromGroup.dispatch(child, this);
}
this.removeChild(child);
var removed = this.removeChild(child);
this.updateZ();
@ -1420,9 +1420,9 @@ Phaser.Group.prototype.remove = function (child, destroy) {
this.next();
}
if (destroy)
if (destroy && removed)
{
child.destroy();
removed.destroy();
}
return true;
@ -1452,11 +1452,11 @@ Phaser.Group.prototype.removeAll = function (destroy) {
this.children[0].events.onRemovedFromGroup.dispatch(this.children[0], this);
}
this.removeChild(this.children[0]);
var removed = this.removeChild(this.children[0]);
if (destroy)
if (destroy && removed)
{
this.children[0].destroy();
removed.destroy();
}
}
while (this.children.length > 0);
@ -1497,11 +1497,11 @@ Phaser.Group.prototype.removeBetween = function (startIndex, endIndex, destroy)
this.children[i].events.onRemovedFromGroup.dispatch(this.children[i], this);
}
this.removeChild(this.children[i]);
var removed = this.removeChild(this.children[i]);
if (destroy)
if (destroy && removed)
{
this.children[i].destroy();
removed.destroy();
}
if (this.cursor === this.children[i])
@ -1530,24 +1530,7 @@ Phaser.Group.prototype.destroy = function (destroyChildren, soft) {
if (typeof destroyChildren === 'undefined') { destroyChildren = true; }
if (typeof soft === 'undefined') { soft = false; }
if (destroyChildren)
{
if (this.children.length > 0)
{
do
{
if (this.children[0].parent)
{
this.children[0].destroy(destroyChildren);
}
}
while (this.children.length > 0);
}
}
else
{
this.removeAll();
}
this.removeAll(destroyChildren);
this.cursor = null;