JackParke Posted September 30, 2017 Share Posted September 30, 2017 I have a PIXI Container with several enemies inside it. Like space invaders the enemies move as a whole and I position the container to move them The problem is: as enemies inside the container "die", the parent container is changing shape and position. It seems to be resizing itself to fit how many children it has. I do not want this to happen. I've tried: 1) destroy() 2) alpha = 0 3) visible = false The alpha solution is the only one where the container does not resize but it only works sporadically. What I mean is sometimes I set alpha=0 and an enemy is still displayed. So we start out like this with the container at x=180: As soon as the left most enemy dies the container resizes and the other enemies appear to jump to the left. Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted September 30, 2017 Share Posted September 30, 2017 In that case, dont modify container position based on its children, use it only to group elements together. If you want to separate width/height, make your own variables with different names in it, like "myWidth" and "myHeight" and use them. Calculate initial values based on initial getBounds(). I think its time to read Container's code: https://github.com/pixijs/pixi.js/blob/dev/src/core/display/Container.js#L16 Its not universal container, it only works for a simple cases, there is no magic inside. You have to code your own, extend this class and do whatever you want with it. Quote Link to comment Share on other sites More sharing options...
JackParke Posted September 30, 2017 Author Share Posted September 30, 2017 Good point! I was calculating the position based on the width of the container and that was "shrinking" as the children "died". The problem is: containers have no anchors so I can only position them based on the top left corner by doing: container.x = container.myX - container.width/2; And as width shrinks this shifts the entire container to the left. I could work around it but it's quite complicated with scaling and sprites of different widths. Seems to me it would be nice to have a fixed width "matrix" container which did not resize and reshape itself. Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted September 30, 2017 Share Posted September 30, 2017 That's just general container with your own Width and Height, just make names of variables different. 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.