Jump to content

Fixed Container Size


JackParke
 Share

Recommended Posts

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:

image.png.d04b038fb8c2cc0fddf982c864b8a1dc.png

As soon as the left most enemy dies the container resizes and the other enemies appear to jump to the left.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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