Skip to content

Commit 5f6fc9d

Browse files
committed
When adding a Group if the parent value is null the Group won't be added to the World, so it's up to you to add it when ready. If parent is undefined it's added to World.
1 parent efd7604 commit 5f6fc9d

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

src/core/Group.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,20 @@
1010
* @classdesc A Group is a container for display objects that allows for fast pooling and object recycling. Groups can be nested within other Groups and have their own local transforms.
1111
* @constructor
1212
* @param {Phaser.Game} game - A reference to the currently running game.
13-
* @param {Phaser.Group|Phaser.Sprite} parent - The parent Group, DisplayObject or DisplayObjectContainer that this Group will be added to. If undefined or null it will use game.world.
13+
* @param {Phaser.Group|Phaser.Sprite|null} parent - The parent Group, DisplayObject or DisplayObjectContainer that this Group will be added to. If undefined it will use game.world. If null it won't be added to anything.
1414
* @param {string} [name=group] - A name for this Group. Not used internally but useful for debugging.
1515
* @param {boolean} [addToStage=false] - If set to true this Group will be added directly to the Game.Stage instead of Game.World.
1616
*/
1717
Phaser.Group = function (game, parent, name, addToStage) {
1818

19+
if (typeof addToStage === 'undefined') { addToStage = false; }
20+
1921
/**
2022
* @property {Phaser.Game} game - A reference to the currently running Game.
2123
*/
2224
this.game = game;
2325

24-
if (typeof parent === 'undefined' || parent === null)
26+
if (typeof parent === 'undefined')
2527
{
2628
parent = game.world;
2729
}
@@ -33,20 +35,16 @@ Phaser.Group = function (game, parent, name, addToStage) {
3335

3436
PIXI.DisplayObjectContainer.call(this);
3537

36-
if (typeof addToStage === 'undefined' || addToStage === false)
38+
if (addToStage)
39+
{
40+
this.game.stage.addChild(this);
41+
}
42+
else
3743
{
3844
if (parent)
3945
{
4046
parent.addChild(this);
4147
}
42-
else
43-
{
44-
this.game.stage.addChild(this);
45-
}
46-
}
47-
else
48-
{
49-
this.game.stage.addChild(this);
5048
}
5149

5250
/**

0 commit comments

Comments
 (0)