Fovi

Correct way to remove sprites / container

4 posts in this topic

Hi, i wondering what is correct way to remove container ?

Is it enough to call destroy function on container, or do i need to remove each sprite first. And what about removing container from root stage ?

Share this post


Link to post
Share on other sites

correct way is

IKnowParentContainer.removeChild(thisSmallThingy);

but sometimes you dont remember where did you put it!

myContainer.parent.removeChild(myContainer);

and sometimes you know that it wont be used anymore AT ALL. Then if all Text and Sprites elements doesnt have textures that you will use in future, you can destroy all textures inside

myContainer.parent.removeChild(myContainer);
myContainer.destroy({children:true, texture:true, baseTexture:true});

But dont worry. If you dont destroy things, javascript gc and our own pixi gc will take care of that in a few minutes.

The only evil thing is generated textures, its better if you destroy renderTextures you created. If you dont know whats a renderTexture, dont worry ;)

Share this post


Link to post
Share on other sites
On 5/20/2017 at 8:37 PM, ivan.popelyshev said:

our own pixi gc will take care of that in a few minutes.

Can you explain this a bit more? Will PIXI automatically destroy(false) unreachable DisplayObjects and/or destroy(true) unreachable Textures? 

Share this post


Link to post
Share on other sites

DisplayObjects are taken by javascript GC. Textures that weren't used for 2-3 minutes or so, will be collected by pixi GC which is turned on by default. You can turn it off if it gives you lags. But if you dont destroy BaseTexture's , images will still live in "PIXI.utils.TextureCache", but they will be in png form (browser optimizes that), which is small compared to fully loaded texture

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.