Skip to content

Commit 76f27ed

Browse files
committed
Added parent, setParent and fixed destroy
1 parent 912b318 commit 76f27ed

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

v3/src/gameobjects/GameObject.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ var GameObject = new Class({
3535
*/
3636
this.scene = scene;
3737

38+
/**
39+
* The parent Container of this Game Object, if any.
40+
* Game Objects do not have to belong to Containers and can exist on the
41+
* Display List on their own.
42+
*
43+
* @property {Phaser.GameObject.Container} parent
44+
* @protected
45+
*/
46+
this.parent = null;
47+
3848
/**
3949
* A textual representation of this Game Object, i.e. `sprite`.
4050
* Used internally by Phaser but is available for your own custom classes to populate.
@@ -149,6 +159,24 @@ var GameObject = new Class({
149159
return this;
150160
},
151161

162+
// Testing: Add this Game Object to a Container parent.
163+
// Can only belong to one Container at once.
164+
// The Container takes over its transform and depth management.
165+
// Call this method with no arguments to remove it from a parent.
166+
setParent: function (newParent)
167+
{
168+
if (newParent)
169+
{
170+
newParent.add(this);
171+
}
172+
else if (this.parent)
173+
{
174+
this.parent.remove(this);
175+
}
176+
177+
return this;
178+
},
179+
152180
/**
153181
* This is a quick chainable alias to the `DataProxy.set` method.
154182
* It allows you to set a key and value in this Game Objects data store.
@@ -269,7 +297,7 @@ var GameObject = new Class({
269297
this.scene.sys.sortChildrenFlag = true;
270298

271299
this.active = false;
272-
this.Visible = false;
300+
this.visible = false;
273301

274302
this.data = undefined;
275303

0 commit comments

Comments
 (0)