Closed qsrahman closed 9 years ago
Currently the addChild
method automatically removes a sprite from its existing parent when it adds it to the new parent.
o.addChild = function(sprite) {
//Remove the sprite from its current parent, if it has one, and
//the parent isn't already this object
if (sprite.parent) {
sprite.parent.removeChild(sprite);
}
//Make this object the sprite's parent and
//add it to this object's `children` array.
sprite.parent = o;
o.children.push(sprite);
};
Adding two functions the the
gameobject
will make it easy to remove it from parent and add an object to a group:Also each function of
gameobject
, group etc. should returnthis
for chaining.