Skip to content

Commit 37713b9

Browse files
committed
Group methods now have optional addToScene and removeFromScene arguments
phaserjs#3080
1 parent 7c2bd98 commit 37713b9

1 file changed

Lines changed: 48 additions & 5 deletions

File tree

v3/src/gameobjects/group/Group.js

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,40 +216,83 @@ var Group = new Class({
216216
}
217217
},
218218

219-
add: function (child)
219+
add: function (child, addToScene)
220220
{
221+
if (addToScene === undefined) { addToScene = false; }
222+
221223
this.children.set(child);
222224

223225
if (this.createCallback)
224226
{
225227
this.createCallback.call(this, child);
226228
}
227229

230+
if (addToScene)
231+
{
232+
this.scene.sys.displayList.add(child);
233+
234+
if (child.preUpdate)
235+
{
236+
this.scene.sys.updateList.add(child);
237+
}
238+
}
239+
228240
return this;
229241
},
230242

231-
addMultiple: function (children)
243+
addMultiple: function (children, addToScene)
232244
{
245+
if (addToScene === undefined) { addToScene = false; }
246+
233247
if (Array.isArray(children))
234248
{
235249
for (var i = 0; i < children.length; i++)
236250
{
237-
this.add(children[i]);
251+
this.add(children[i], addToScene);
238252
}
239253
}
240254

241255
return this;
242256
},
243257

244-
remove: function (child)
258+
remove: function (child, removeFromScene)
245259
{
260+
if (removeFromScene === undefined) { removeFromScene = false; }
261+
246262
this.children.delete(child);
247263

264+
if (removeFromScene)
265+
{
266+
this.scene.sys.displayList.remove(child);
267+
268+
if (child.preUpdate)
269+
{
270+
this.scene.sys.updateList.remove(child);
271+
}
272+
}
273+
248274
return this;
249275
},
250276

251-
clear: function ()
277+
clear: function (removeFromScene)
252278
{
279+
if (removeFromScene === undefined) { removeFromScene = false; }
280+
281+
if (removeFromScene)
282+
{
283+
for (var i = 0; i < children.length; i++)
284+
{
285+
gameObject = children[i];
286+
287+
this.scene.sys.displayList.remove(gameObject);
288+
289+
if (gameObject.preUpdate)
290+
{
291+
this.scene.sys.updateList.remove(gameObject);
292+
}
293+
}
294+
}
295+
253296
this.children.clear();
254297

255298
return this;

0 commit comments

Comments
 (0)