Why a game object rendered twice

Recently, I read the documentation of Phaser and found some conflicts between container.add and gameobject.addtodisplaylist. Therefore, I wrote the following test code:

let image = this.make.image({x : 100, y : 100, key : "block", add : false})
container.add(image);
image.addToDisplayList()

The image in above code rendered twice.

This is the document description for the container:

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.

And this is the description of addToDisplayList:

If a Game Object is not on any display list, it will not be rendered;

But in my personal understanding, a gameobject actually has two rendering paths: container’s internal list or gameobject’s displayList. This seems to be the reason for the above phenomenon, which confuses me a bit.

online code:https://phaser.io/sandbox/ujL3To1A

1 Like

:wave:

  • addToDisplayList() removes only from other Display Lists (e.g., Layers), but not from Containers.
  • If a Game Object is not on any Display List (either directly or as an ancestor of a Container or Layer), it will not be rendered.