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

Mouse events have wrong position afters canvas is transformed #772

Open
koko236 opened this issue Jun 8, 2016 · 7 comments
Open

Mouse events have wrong position afters canvas is transformed #772

koko236 opened this issue Jun 8, 2016 · 7 comments
Labels

Comments

@koko236
Copy link

koko236 commented Jun 8, 2016

I was wondering why my mouse events are not working on a canvas animation. Turned out they do, but the div holding the canvas was rotated 180 degrees (using css transform) and the 'click map' worked as if there is no transformation. So clicking on the old unrotated position works even though though the sprite is visually somewhere else now.

@gskinner gskinner added the bug label Jun 8, 2016
@gskinner
Copy link
Member

gskinner commented Jun 8, 2016

Right. This is a known issue due to the way we had to implement mouse events to support mouse movements outside the canvas, and all supported browsers. I'm not sure we're going to be able to fix it, but I will take a look and see if I can come up with any other ideas. Input is welcome.

@koko236
Copy link
Author

koko236 commented Jun 8, 2016

Is there any known workaround, like if I know the transform I can reverse transform the mouse position on my own and make a hit test? I used to do flash a lot, but I'm not extremely familiar with easeljs hit testing mechanism.

@meomar
Copy link

meomar commented Feb 28, 2018

Is this issue fixed ? is there any workaround ?

@atmanugraha
Copy link

Hi all!

I also found the same issue when trying to transform (zoom in) canvas using mouse wheel, Stage.mouseX value is only updated after I scroll twice (I mean, when you scroll your mouse you can feel the click-feel. After twice click, the Stage.mouseX is updated).

But when I only scroll once (1 click), and then press left mouse button, the Stage.mouseX is updated.
I'm not really sure why it behaves like this. I hope this issue will be fixed soon :)

@lannymcnie
Copy link
Member

@atmanugraha that sounds unrelated to this issue. What browser is this happening in?

Are you expecting a stage mouse-position update from a mousewheel scroll? There isn't any built-in support for mousewheel, which is why left-click will update those values for you. Chances are good you get an update when you move the mouse slightly, or maybe the browser is running some sort of mousemove for you unreliably. Either way, it might make sense to patch in some mousewheel logic to the Stage, so it keeps the mouse position up to date.

@atmanugraha
Copy link

Hi @lannymcnie !
I'm sorry I didnt know that there's not any built-in support for mousewheel scroll to update mouse position, because what I experienced is when I scroll it one step, the mouse.X and mouse.Y value is automatically updated. It makes me assumed that EaselJS has something to do with the position values.

But it doesn't matter now since I have created my own logic to detect its real position after using mousewheel. :)

@stfujnkk
Copy link

stfujnkk commented Oct 5, 2022

@atmanugraha that sounds unrelated to this issue. What browser is this happening in?

Are you expecting a stage mouse-position update from a mousewheel scroll? There isn't any built-in support for mousewheel, which is why left-click will update those values for you. Chances are good you get an update when you move the mouse slightly, or maybe the browser is running some sort of mousemove for you unreliably. Either way, it might make sense to patch in some mousewheel logic to the Stage, so it keeps the mouse position up to date.

I have a similar problem that when the canvas scrolls or zooms, the coordinatesstage.mouseX, stage.mouseY of the mouse relative to the canvas are not updated unless you move or click the mouse.
I have solved it myself and I'm thinking about coding a PR for this problem.

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

No branches or pull requests

6 participants