Either I'm misinterpreting normal actions or I found a bug

Hello, I should start off by saying that I’m new-ish to phaser. So it’s very possible that I’m misunderstanding the situation. Either way the issue is when you have:
container1, container2, and sprite.
container2.add(sprite);
container1.add(container2);
container1.remove(container2);
The issue lies in that container2 (or at least the sprite)completely disappears from view.

If you want to test it, go to this example:
http://labs.phaser.io/edit.html?src=src/game%20objects/container/nested%20container%20visibility.js&v=3.23.0
and change line 32 to say “container1.remove(container2);”

Something I did notice trying to find other instances of this issue. When a sprite is added to a container, it is removed from the game’s display list and added to the container’s display list.
As shown in: https://phaser.io/phaser3/devlog/120. I don’t know if this is how it still works, but it is what I assume. My guess is that for some reason container2 isn’t added back to the main display list. The reason for this is that if you add:
“this.input.once(‘pointerup’, function () {
container1.add(container2);
});”
after the pointerdown listener, it appears back. It doesn’t seem to let you click again, but nonetheless. I’m lost in terms of what to do.

So if there is anything else I can do to help explain my problem, let me know.

Lastly, this is a bit off-topic, if anyone knows a good way to make a menu of objects that one could infinitely select and place somewhere else in the scene, like a super Mario maker level editor or rpg map editor, that would be helpful.

Hi, I’m going to try help if I understand well… I think you are right with what you found first.

When a Game Object is added to a Container, the Container becomes responsible for the rendering of it. By default it will be removed from the Display List and instead added to the Containers own internal list.

Here is the doc
https://photonstorm.github.io/phaser3-docs/Phaser.GameObjects.Container.html

But… you can add and remove and add again, or setVisible to true or false if you still want the GameObject to be processed somehow. Even in the example you pointed works, the only thing maybe confusing is that “this.input.once” will be executed only once, try it with “this input.on”.

If by iniftely select and place objects you mean like a map or level editor… one of the most common way is using for example Tiled (https://www.mapeditor.org/) to create maps/levels and then use Phaser to read it.

I don’t know if I got your points, I hope this helps.

This is intentional, you need to add it yourself.

this.sys.displayList.add(container2);
// or
this.children.add(container2);
1 Like

Thanks for pointing out once, I didn’t see that. I was just slightly confused by the example. I have used input.on and the issue remains. setVisible did nothing. I will probably do what samme mentioned in their post.

As for Tiled, I’m practically looking to make a version of Tiled in phaser. It’s a Tower Defense game where you have a selection of towers, but I don’t know a good way to implement this menu or if phaser should even be used for this use case.

Thank you for your help

You are welcome.
Anyway, just in cas it helps, this is what I meant in the commented example:

...
var v = true;
this.input.on('pointerdown', function () {
    v = !v;
    container2.setVisible(v);
});