mirror of
https://github.com/photonstorm/phaser
synced 2024-11-27 15:12:18 +00:00
Group methods now have optional addToScene
and removeFromScene
arguments
#3080
This commit is contained in:
parent
7c2bd98e44
commit
37713b9f4a
1 changed files with 55 additions and 12 deletions
|
@ -216,8 +216,10 @@ var Group = new Class({
|
|||
}
|
||||
},
|
||||
|
||||
add: function (child)
|
||||
add: function (child, addToScene)
|
||||
{
|
||||
if (addToScene === undefined) { addToScene = false; }
|
||||
|
||||
this.children.set(child);
|
||||
|
||||
if (this.createCallback)
|
||||
|
@ -225,31 +227,72 @@ var Group = new Class({
|
|||
this.createCallback.call(this, child);
|
||||
}
|
||||
|
||||
if (addToScene)
|
||||
{
|
||||
this.scene.sys.displayList.add(child);
|
||||
|
||||
if (child.preUpdate)
|
||||
{
|
||||
this.scene.sys.updateList.add(child);
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
addMultiple: function (children)
|
||||
addMultiple: function (children, addToScene)
|
||||
{
|
||||
if (addToScene === undefined) { addToScene = false; }
|
||||
|
||||
if (Array.isArray(children))
|
||||
{
|
||||
for (var i = 0; i < children.length; i++)
|
||||
{
|
||||
this.add(children[i]);
|
||||
this.add(children[i], addToScene);
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
remove: function (child)
|
||||
remove: function (child, removeFromScene)
|
||||
{
|
||||
if (removeFromScene === undefined) { removeFromScene = false; }
|
||||
|
||||
this.children.delete(child);
|
||||
|
||||
if (removeFromScene)
|
||||
{
|
||||
this.scene.sys.displayList.remove(child);
|
||||
|
||||
if (child.preUpdate)
|
||||
{
|
||||
this.scene.sys.updateList.remove(child);
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
clear: function ()
|
||||
clear: function (removeFromScene)
|
||||
{
|
||||
if (removeFromScene === undefined) { removeFromScene = false; }
|
||||
|
||||
if (removeFromScene)
|
||||
{
|
||||
for (var i = 0; i < children.length; i++)
|
||||
{
|
||||
gameObject = children[i];
|
||||
|
||||
this.scene.sys.displayList.remove(gameObject);
|
||||
|
||||
if (gameObject.preUpdate)
|
||||
{
|
||||
this.scene.sys.updateList.remove(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.children.clear();
|
||||
|
||||
return this;
|
||||
|
|
Loading…
Reference in a new issue