Jump to content

Correct way to remove sprites / container


Fovi
 Share

Recommended Posts

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 ?

Link to comment
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 ;)

Link to comment
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? 

Link to comment
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

Link to comment
Share on other sites

  • 1 year later...

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...