d13 Posted May 17, 2014 Share Posted May 17, 2014 Does anyone know if Pixi has some kind of global `remove()` function?I'm looking for a way to remove all instances of a sprite from the stage and any containers it might be in. Or, do I only need to use `removeChild` on its current container?Can a sprite only be a child of one DisplayObjectContainer at a time? Quote Link to comment Share on other sites More sharing options...
Kuboid Posted May 18, 2014 Share Posted May 18, 2014 A sprite can only be a child of one other container. If you dont know where you added your sprite, you can remove it that way: sprite.parent.removeChild(sprite).But I think its better you know the parent and call removeChild from there. Hope it helps Quote Link to comment Share on other sites More sharing options...
d13 Posted May 18, 2014 Author Share Posted May 18, 2014 Thanks that does help! I've noticed that if you do this: stage.addChild(blueSprite); and then this: container.addChild(blueSprite); ... then `blueSprite` is removed from the stage's `children` list and added to the container's. So Pixi seems to be automatically tracking the sprite's parent and managing the display list hierarchy.If this is really what's happening, that would be great, because it will save me from building a sub-system to do that management myself. Or, do I explicitly need to use `removeChild` before adding a sprite to a new parent? Quote Link to comment Share on other sites More sharing options...
xerver Posted May 18, 2014 Share Posted May 18, 2014 Pixi is a scene graph, no need to write a scene graph on top of it. A node only has one parent in a tree but many children. If you add a child to a container, when that child is already in another container it is first removed from it's current parent then added to the new one. Quote Link to comment Share on other sites More sharing options...
d13 Posted May 18, 2014 Author Share Posted May 18, 2014 Thanks for clarifying that! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.