Jump to content

How to clearup Graphics / Container the correct way?


Flippsor
 Share

Recommended Posts

Hey guys,

i am using PIXI.js for some months now and i am pretty happy with it. I am building a top down 2D CAD Software which uses a lot of PIXI.Graphics to draw Objects like Arrows/Lines/Rectangles etc. These are often combined in a PIXI.Container with parent/child relationship. 

So now my questions:

Remove PIXI.Container (PIXI.Graphics) the right way
If i have to remove a Graphics object, i use removeChild() from parent container.
Is this everything i need to do? Or do i have to call .destroy() on the child, too?

Redraw Graphics
If i need to redraw a Graphic i can choose to either addChild/removeChild a new Graphic or just use the same Graphic with .clear() again.
What technique is more performant and should be used?

Thanks in advance!

Link to comment
Share on other sites

 I am building a top down 2D CAD Software 
What technique is more performant and should be used?
Ideally, you need to read all the source code, understand all the allocation places and decide for yourself whether to use it as is, patch it, or make a new one.

destroy() also takes care of videomemory, in case object wasnt small and had a webgl VAO and buffers bound. Its not disposed automatically.

clear() kinda empties js arrays, i dont know what else to say about it - there are many places of allocation when you fill the graphics.

General optimization is like in all other renderers - separate your scene to graphics objects but not too many :) Use chunks if you know what is it.

Link to comment
Share on other sites

Sorry for my late answer and thanks for your feedback.

So to summarize your feedback i should follow these rules ?!?

- stick your graphics together when possible. Dont use addchild when sticking graphics together instead draw all in one graphic object
- use .clear() to redraw graphics !?!
 

I am not quite sure about to use or not to use destroy(). How do i know if the object had an webgl VAO and buffers bound? Is the solution always to destroy() an object after removeChild()?

Link to comment
Share on other sites

Is the solution always to destroy() an object after removeChild()?

Yes, for Graphics. Also, destroy() calls removeChild automatically.

Btw, small graphics objects (<100 vertices, no arcs) dont have VAO, they just get batched with sprites.

Edited by ivan.popelyshev
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...