Sign in to follow this  
canvasman

Remove or Destroy Sprite

Recommended Posts

I am creating multiple sprites from same texture in PIXI v5, I have few questions:

 

1. When I am not going to use specific sprite anymore, do I need to remove the sprite from container with container.removeChild(sprite) before calling sprite.destroy()?

I call destroy without arguments because I don't want to destroy the texture which I might use later to create more sprites.

 

2. What is the difference between calling container.removeChild(sprite) and sprite.destroy(without arguments)?

Does the GC collect everything regarding the sprite in either way? (except the texture which is in the GPU memory).

 

Thanks!

Edited by canvasman

Share this post


Link to post
Share on other sites

1. destroy() in sprites are actually a over-, javascript GC will take it anyway just like any other object. It could be different if Textures had links to sprites (events, subscribe) but they aren't. You remove sprite from container and pixi forgets about it.

2. sprite fields are getting slaughtered and its not usable anymore, many things will just throw error when you try to use them :)

Share this post


Link to post
Share on other sites
7 minutes ago, ivan.popelyshev said:

1. destroy() in sprites are actually a over-, javascript GC will take it anyway just like any other object. It could be different if Textures had links to sprites (events, subscribe) but they aren't. You remove sprite from container and pixi forgets about it.

2. sprite fields are getting slaughtered and its not usable anymore, many things will just throw error when you try to use them :)

Okay! Regarding the #1 question, would you call both removeChild() and .destroy() in that order or only either in my case when you don't need to use that same sprite later?

Share this post


Link to post
Share on other sites
7 hours ago, themoonrat said:

I'd just call destroy

As part of the DisplayObject's destroy function, it has the following code, that removes itself from any parent it has 

if (this.parent)
{
    this.parent.removeChild(this);
}

Moonrat is the best! Thanks dude :)

Share this post


Link to post
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...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.