My goal is get live updating input from x and y position of my mouse. The y position works great, but when I went to add in the x position, I can't get anything but 'NaN'.
Why isn't this working for the X position as well? Is this not how to pass an object through a function? Is multiple objects the problem?
Here is my code:
canvas.addEventListener('mousemove',
function(evt){
var mousePos = calculateMousePosY(evt);
paddle1Y = mousePos.y;
//HERE IS WHERE I WANT X POSITION AS WELL
paddle1X = mousePos.x; //Why doesn't this work?
});
function calculateMousePos(evt){
var rect = canvas.getBoundingClientRect();
var root = document.documentElement;
var mouseX = evt.clientX - rect.left - root.scrollleft;
var mouseY = evt.clientY - rect.top - root.scrollTop;
return{
x:mouseX,
y:mouseY
}