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

ScaleManager miscalculates mouse position should the canvas move on the page without changing size #5884

Closed
jameswilddev opened this issue Oct 25, 2021 · 1 comment

Comments

@jameswilddev
Copy link

Version

  • Phaser Version: 3.55.2
  • Operating system: macOS 11.6
  • Browser: Google Chrome 94.0.4606.81 (Official Build) (x86_64)

Description

When mouse pointer locations are converted from page space into canvas space, ScaleManager.transformY is called which uses a cache of the canvas's dimensions.

This information is refreshed in ScaleManager.updateBounds.

This is triggered (via ScaleManager.refresh) though multiple means such as:

In the case that the canvas's width or height are adjusted by surrounding DOM or style changes, the interval will trigger a refresh of this cached bounding box.

However, it calls into getParentBounds to determine whether its cache is stale, which only checks width and height, not that the position of the canvas on the page has changed.

Therefore, if the canvas is moved on the page without altering its size (for example if it is below a collapsible section which is expanded or collapsed) Phaser is unaware that the canvas has moved and all mouse input is offset until the window is resized.

Example Test Code

https://codepen.io/jameswilddev/pen/xxLqVKr

This will show a simple rectangle which changes color when the mouse hovers over it.

After two seconds, an input will be added further up the page which shifts the canvas down approximately 25px.

After this point, all mouse input is offset vertically by the same amount; you can trigger the color change by hovering over the area above the rectangle, but the bottom 25px of the rectangle no longer triggers a color change.

Additional Information

Nothing to add.

@photonstorm
Copy link
Collaborator

Thank you for submitting this lovely detailed 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
Projects
None yet
Development

No branches or pull requests

2 participants