Stan. Posted June 7, 2021 Share Posted June 7, 2021 Currently working on a project where I often have to bring an object to the front in a container. Currently I achieve this with the following code: bringContainerToFront(container) { const parent = container.parent parent.removeChild(container) parent.addChild(container) } Is the a more succinct way that just removing the child and adding it back again? Any advice would be greatly appreciated. Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted June 7, 2021 Share Posted June 7, 2021 About adding/removing performance: there's an array inside. Guess the cost. https://github.com/pixijs/pixijs/blob/9c1861b83f2d2bdb75235ada648d76d465ba0071/packages/display/src/Container.ts#L144-L181 There is different way: use "@pixi/layers" , https://pixijs.io/examples/#/plugin-layers/bringToTop.js . It goes through all the tree every frame and marks which objects have to be rendered in which containers, temporarily, without changing actual parent. Create a top layer, make sure its always on top of your stage (the last child, put all other objects in other container maybe). Do "sprite.parentLayer = topLayer" every time you want to bring a sprite to front. This operation wont actually move anything anywhere. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.