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
More robust calculation of touch/click position relative to canvas #13
Comments
Hi @pardo-bsso, thanks for your suggestion, I will try the code in the test page. |
Hi @pardo-bsso, I have read the documentation you have indicated, but as reported in this link it is a Working Draft, so for now it is not definitive. For this reason, even if the code would be much cleaner, I don't think I will adopt this solution for the moment. I have tried the code you suggested, and it work well in desktop browser, but it doesn't work on mobile device. You have tested it on mobile? |
I'm experiencing the same issue (both with mouse and touch on desktop and mobile): Unless the page is scrolled all the way to the top the joystick keeps dragging to the bottom. Adding this line to both
|
Hi @bobboteck , thanks for this library.
While trying it inside a page with a complex layout, using canvas.offsetParent.offsetLeft (and Top) inside of onTouchMove() and onMouseMove() reported (correctly) the offsets for the closest positioned parent element.
However, its offsetTop was 0 but the event.pageY was something like 400 and that made the Y axis of the joystick unusable.
Nowadays most browsers support the clientX and clientY properties on events that report the desired value (see https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/offsetX and related)
We ended up patching the methods like:
and that made it work like a charm.
I don't know if you had other reason for the original code but this is related to issues like #10, #11 and #12.
Thanks
The text was updated successfully, but these errors were encountered: