Skip to content

setVisible not working for DOM elements in a container #5816

@prakol16

Description

@prakol16

Version

  • Phaser Version: 3.55.2
  • Operating system: Ubuntu
  • Browser: Tested on Chrome and Firefox

Description

It seems like the fix in #4486 is no longer working. When the visibility of the parent container is changed, the DOM node is still visible. I am able to determine that it is because preUpdate is not being called on DOM elements, though I am not sure why.

Example Test Code

class MainScene extends Phaser.Scene {
    create() {
        const text = new Phaser.GameObjects.DOMElement(this, 0, 0, "span", { color: "white" }, "Hello");
        const container = this.add.container(50, 50, [text]);
        this.time.delayedCall(1000, () => {
            console.log("Setting container visibility to false");
            container.setVisible(false);
            // If we forcefully call preupdate on the next update
            // then the text correctly disappears
            // this.events.once("update", () => {
            //     text.preUpdate();
            // });
        });
    }
}

See a demo: https://codepen.io/prakol16/pen/rNwVyvv

Additional Information

In addition, perhaps the preUpdate code should be moved to a preStep event on the game. The reason for this is because if a scene is paused, the visibility of various objects can still change, but preUpdate will never be called. Similarly, if the container/its children are changed to be inactive with setActive(false), we'd expect the visibility to still be controlled separately by setVisible, but instead, the visibility of the DOM element will no longer change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions