-1

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

Ben
  • 31
  • 6

1 Answers1

1

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

BelKed
  • 87
  • 7
  • No problem :) If you feel an answer solved the problem, please mark it as 'accepted' by clicking the green check mark. – BelKed Jan 08 '22 at 13:15