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