Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setVisible not working for DOM elements in a container #5816

Closed
prakol16 opened this issue Aug 26, 2021 · 5 comments · Fixed by #5819
Closed

setVisible not working for DOM elements in a container #5816

prakol16 opened this issue Aug 26, 2021 · 5 comments · Fixed by #5819

Comments

@prakol16
Copy link

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.

@samme
Copy link
Contributor

samme commented Aug 26, 2021

It still works, use

const text = this.add.dom(0, 0, "span", { color: "white" }, "Hello");

@samme
Copy link
Contributor

samme commented Aug 26, 2021

It doesn't work, in fact. 😄

@prakol16
Copy link
Author

The more general issue is #5817. In fact sprite animations, (more generally, anything with preUpdate) don't work in containers either, except in certain circumstances. Maybe this issue should be closed in favor of that one?

@samme
Copy link
Contributor

samme commented Aug 26, 2021

Well, this still works:

const text = this.add.dom(0, 0, "span", { color: "white" }, "Hello");

this.add.container(0, 0, [text]).setVisible(false);
// `text` will also be invisible

I agree that this issue would be better addressed without preUpdate() though, so I would keep it open.

samme added a commit to samme/phaser that referenced this issue Aug 27, 2021
Check parent visibility in preRender()

Fixes phaserjs#5816
@photonstorm
Copy link
Collaborator

Thank you for submitting this issue. We have fixed this and the fix has been pushed to the master branch. It will be part of the next release. If you get time to build and test it for yourself we would appreciate that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants