Skip to content

Commit 933e193

Browse files
committed
Group.destroy has a new optional argument destroyChildren which will automatically call destroy on all children of a Group if set to true (the default is false, hence it doesn't change the public API). Fix phaserjs#3246
1 parent 3aa95b4 commit 933e193

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,20 @@
66

77
* A new property was added to Matter.World, `correction` which is used in the Engine.update call and allows you to adjust the time
88
being passed to the simulation. The default value is 1 to remain consistent with previous releases.
9+
* Group.destroy has a new optional argument `destroyChildren` which will automatically call `destroy` on all children of a Group if set to true (the default is false, hence it doesn't change the public API). Fix #3246 (thanks @DouglasLapsley)
910

1011

1112
### Bug Fixes
1213

1314
* In the WebGL Render Texture the tint of the texture was always set to 0xffffff and therefore the alpha values were ignored. The tint is now calculated using the alpha value. Fix #3385 (thanks @ger1995)
1415
* The RenderTexture now uses the ComputedSize component instead of Size (which requires a frame), allowing calls to getBounds to work. Fix #3451 (thanks @kuoruan)
15-
* PathFollower.start has been renamed to `startFollow`, but PathFollower.setPath was still using PathFollower.start. (thanks @samid737)
16+
* PathFollower.start has been renamed to `startFollow`, but PathFollower.setPath was still using `PathFollower.start` (thanks @samid737)
1617

1718
### Updates
1819

20+
* The RTree library (rbush) used by Phaser 3 suffered from violating CSP policies by dynamically creating Functions at run-time in an eval-like manner. These are now defined via generators. Fix #3441 (thanks @jamierocks @Colbydude)
21+
22+
1923

2024

2125

src/gameobjects/group/Group.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,9 +894,28 @@ var Group = new Class({
894894
*
895895
* @method Phaser.GameObjects.Group#destroy
896896
* @since 3.0.0
897+
*
898+
* @param {boolean} [destroyChildren=false] - Call `GameObject.destroy` on all children of this Group?
897899
*/
898-
destroy: function ()
900+
destroy: function (destroyChildren)
899901
{
902+
if (destroyChildren === undefined) { destroyChildren = false; }
903+
904+
if (destroyChildren)
905+
{
906+
var children = this.children;
907+
908+
for (var i = 0; i < children.size; i++)
909+
{
910+
var gameObject = children.entries[i];
911+
912+
// Remove the event hook first or it'll go all recursive hell on us
913+
gameObject.off('destroy', this.remove, this);
914+
915+
gameObject.destroy();
916+
}
917+
}
918+
900919
this.children.clear();
901920

902921
this.scene = undefined;

0 commit comments

Comments
 (0)