Ask coding questions

← Back to all posts
How do you see where the user clicks JavaScript
h
okalisl

I have been working on a game that needs shooting. Everything has been going fine until I had the question: How do you see where the user clicks on the screen?

Answered by SixBeeps [earned 5 cycles]
View Answer
Voters
okalisl
Comments
hotnewtop
SixBeeps

You could have your canvas element or whatever you're using to render the game subscribe to the click event. Whenever the click event is fired, the event has properties that correspond to the various coordinates of the click. Something like this should get you going.

okalisl

Thanks @SixBeeps!