0
How do I get the x and y of a click using javascript?
So Im making a 2d html game and Im tryna get the x and y of a click and turn it into a variable. How would I do that? Edit:I've been trying a different method but it broke the game for some reason so I was stuck. Thnx
1 Odpowiedź
+ 3
i use the event object parameter in the callback function for that.
for example, in the addeventlistener:
addEventListener("click", function(event) {
console.log(event.x);
console.log(event.y);
});
The above function will be fired when the user clicks anywhere in the document.
https://code.sololearn.com/WKOTJchCY1IK/?ref=app