Added parent, setParent and fixed destroy

This commit is contained in:
Richard Davey 2017-12-15 04:08:05 +00:00
parent 912b318d3e
commit 76f27ed706

View file

@ -35,6 +35,16 @@ var GameObject = new Class({
*/
this.scene = scene;
/**
* The parent Container of this Game Object, if any.
* Game Objects do not have to belong to Containers and can exist on the
* Display List on their own.
*
* @property {Phaser.GameObject.Container} parent
* @protected
*/
this.parent = null;
/**
* A textual representation of this Game Object, i.e. `sprite`.
* Used internally by Phaser but is available for your own custom classes to populate.
@ -149,6 +159,24 @@ var GameObject = new Class({
return this;
},
// Testing: Add this Game Object to a Container parent.
// Can only belong to one Container at once.
// The Container takes over its transform and depth management.
// Call this method with no arguments to remove it from a parent.
setParent: function (newParent)
{
if (newParent)
{
newParent.add(this);
}
else if (this.parent)
{
this.parent.remove(this);
}
return this;
},
/**
* This is a quick chainable alias to the `DataProxy.set` method.
* It allows you to set a key and value in this Game Objects data store.
@ -269,7 +297,7 @@ var GameObject = new Class({
this.scene.sys.sortChildrenFlag = true;
this.active = false;
this.Visible = false;
this.visible = false;
this.data = undefined;