+ 4
(solved) Long click button
I'm making a game with a big world, but clicking on the left and right buttons just moves the player some pixels to left or right. It's slow and boring. It would be nice if you could long click on the buttons, and move until you release the button. How can I do that? https://code.sololearn.com/WZfk7yErVKpa/?ref=app
2 Réponses
+ 5
You have to update your game all the time (with requestAnimationFrame for example), and use these event listeners: mousedown and mouseup. You can then check with the function if the button is pressed down (maybe with a boolean value), and make that value false when it's up. If you want it to make it run on phones, you can use the touchstart and touchend events
+ 4
Airree
Thanks!