Jump to content

[PIXI] Remove all instances?


d13
 Share

Recommended Posts

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...