Issue
I am making a game in JavaScript and I would like to define a variable as the Mouse Y axis. Please don't make the code un-necessarily complex if you can help it. That's all
Solution
You can use addEventListener
for "mousemove"
, which on each movement of mouse prints out it coordinates:
document.addEventListener("mousemove", () => {
let mousex = event.clientX; // Gets Mouse X
let mousey = event.clientY; // Gets Mouse Y
console.log([mousex, mousey]); // Prints data
});
Code credits: https://www.codegrepper.com/code-examples/javascript/how+to+get+mouse+x+and+y+in+javascript
Answered By - BelKed
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.