phaserjs / phaser

Phaser is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.
https://phaser.io
MIT License
37.16k stars 7.1k forks source link

Fixing DomElement position when camera zoom != 1 #6819

Closed moufmouf closed 2 months ago

moufmouf commented 6 months ago

This PR (delete as applicable)

Describe the changes below:

When the camera zoom is set to any other value than one, if a dom element origin if set to anything other than 0, the final position of the DOM was incorrect.

The complete bug is described in #6817.

I traced this back to the DOMElementCSSRenderer. After some trial and error, I realized the translation needed to be applied after camera multiplication and not at the beginning.

With this change, DOMElements are correctly positioned.

This closes #6817 and https://github.com/workadventure/workadventure/issues/3936 (where you can see a video of the issue in action)

Note: I very much suspect the same error happens in the "if" clause, if a parent matrix is set. However, I don't know how to test this. Any help is welcome to help me test this out.

moufmouf commented 6 months ago

Note: this also fixes those issues:

moufmouf commented 5 months ago

Note: I very much suspect the same error happens in the "if" clause, if a parent matrix is set. However, I don't know how to test this. Any help is welcome to help me test this out.

With the advice of @rexrainbow I was able to test the case where the parent matrix is set by adding the DOMElement inside a container. Hopefully, this case was already working correctly so does not need a fix. See https://phaser.io/sandbox/FRfpYx4G

So this PR is ready to merge! :+1:

HugoAverty commented 2 months ago

Would it be possible to merge this PR? I'm super interested and other issues have come up on this subject. @zekeatchan / @photonstorm