0

[Solved] Onclick doesn't work while screen is touched

I'm working on a code with a button using onlick (for jumping). But it only works when you're not touching the screen anywhere else (while you're touching the buttons for moving, the onclick button doesn't work). Is there a way to solve that problem? Here's the code: https://code.sololearn.com/WpCApR631liy/?ref=app

26th May 2021, 12:36 PM
C. Scheler
C. Scheler - avatar
2 Answers
+ 3
onclick is designed for mouse click... even if it is emulated by touch devices, it is expected to handle click/touch to more than one point at a time ^^ you should look at touch events rather than mouse events to be able to handle multi-touch points: https://developer.mozilla.org/en-US/docs/Web/API/Touch_events ... but that's quite more tricky to use than basic mouse events, and would not work on pc (non touch devices) ;P you could test / log the event objects passed as argument on touch handlers in this (old) code of mine: https://code.sololearn.com/WO8wrPV40Fzn/?ref=app
26th May 2021, 4:57 PM
visph
visph - avatar
+ 1
Okay, I replaced "onclick" with "ontouchstart". I'll add controls for PC keyboards later.
26th May 2021, 5:08 PM
C. Scheler
C. Scheler - avatar