Skip to content

Commit f70e4d7

Browse files
committed
Fixed the use of the destroy parameter in Group.removeAll and related functions (thanks @AnderbergE, fix phaserjs#717)
1 parent 2fd7040 commit f70e4d7

2 files changed

Lines changed: 12 additions & 27 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ Version 2.0.4 - "Mos Shirare" - in development
7272
### Bug Fixes
7373

7474
* The main Timer loop could incorrectly remove TimeEvent if a new one was added specifically during an event callback (thanks @garyyeap, fix #710)
75+
* Fixed the use of the destroy parameter in Group.removeAll and related functions (thanks @AnderbergE, fix #717)
76+
7577

7678

7779
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.

src/core/Group.js

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,7 +1411,7 @@ Phaser.Group.prototype.remove = function (child, destroy) {
14111411
child.events.onRemovedFromGroup.dispatch(child, this);
14121412
}
14131413

1414-
this.removeChild(child);
1414+
var removed = this.removeChild(child);
14151415

14161416
this.updateZ();
14171417

@@ -1420,9 +1420,9 @@ Phaser.Group.prototype.remove = function (child, destroy) {
14201420
this.next();
14211421
}
14221422

1423-
if (destroy)
1423+
if (destroy && removed)
14241424
{
1425-
child.destroy();
1425+
removed.destroy();
14261426
}
14271427

14281428
return true;
@@ -1452,11 +1452,11 @@ Phaser.Group.prototype.removeAll = function (destroy) {
14521452
this.children[0].events.onRemovedFromGroup.dispatch(this.children[0], this);
14531453
}
14541454

1455-
this.removeChild(this.children[0]);
1455+
var removed = this.removeChild(this.children[0]);
14561456

1457-
if (destroy)
1457+
if (destroy && removed)
14581458
{
1459-
this.children[0].destroy();
1459+
removed.destroy();
14601460
}
14611461
}
14621462
while (this.children.length > 0);
@@ -1497,11 +1497,11 @@ Phaser.Group.prototype.removeBetween = function (startIndex, endIndex, destroy)
14971497
this.children[i].events.onRemovedFromGroup.dispatch(this.children[i], this);
14981498
}
14991499

1500-
this.removeChild(this.children[i]);
1500+
var removed = this.removeChild(this.children[i]);
15011501

1502-
if (destroy)
1502+
if (destroy && removed)
15031503
{
1504-
this.children[i].destroy();
1504+
removed.destroy();
15051505
}
15061506

15071507
if (this.cursor === this.children[i])
@@ -1530,24 +1530,7 @@ Phaser.Group.prototype.destroy = function (destroyChildren, soft) {
15301530
if (typeof destroyChildren === 'undefined') { destroyChildren = true; }
15311531
if (typeof soft === 'undefined') { soft = false; }
15321532

1533-
if (destroyChildren)
1534-
{
1535-
if (this.children.length > 0)
1536-
{
1537-
do
1538-
{
1539-
if (this.children[0].parent)
1540-
{
1541-
this.children[0].destroy(destroyChildren);
1542-
}
1543-
}
1544-
while (this.children.length > 0);
1545-
}
1546-
}
1547-
else
1548-
{
1549-
this.removeAll();
1550-
}
1533+
this.removeAll(destroyChildren);
15511534

15521535
this.cursor = null;
15531536

0 commit comments

Comments
 (0)