melonJS icon indicating copy to clipboard operation
melonJS copied to clipboard

Placing renderables on Containers within containers results in strange positioning of them.

Open wpernath opened this issue 3 years ago • 0 comments

Describe the bug If you have containers inside containers, both with floating=true and/or false, the positions of displayable components like texts, images or sprites are sometimes weird.

Use Case: I have a state / stage, which has a full screen (floating = true) transparent background container. On top of that container I am adding several other non floating containers with buttons and text inside (for example a level chooser component).

BackgroundContainer(0,0,1000,700); MenuContainer(5, 100, 900, 700); CentralContainer(50, 100, 800, 300); BitmapText(5, 5); Sprite(100, 5);

At the end I am expecting that BitmapText will be rendered at (absolute) position of (x=60, y=200). Right now it will be rendered outside of its CentralContainer, although floating is set to false on all containers except BackgroundContainer.

I agree that adding a component to a (deeply) nested container is a costly action, but I'd need it only for menu states, not for in-game states.

Container.updateBounds() does not do the trick. Even if I have set ´Container.enableChildBoundsUpdate=true`

So it's either a bug in component placement or I it's too late today and I can't see where my mistake is.

Expected behavior Adding components like Sprites, Images, Texts should respect their container's boundaries and relative positions, even if there are nested containers.

wpernath avatar Sep 05 '22 23:09 wpernath