How can I get the coordinates of the cursor on the screen properly ?
I tried using event.clientX
and event.clientY
however it only works in certain cases .
If I try to make a special function for it it works
stage = new createjs.Stage("myCanvas");
circle = new createjs.Shape();
circle.graphics.beginFill("red").drawCircle(0, 0, 40);
createjs.Ticker.addEventListener("tick", handleTick);
function handleTick() {
if (circle.x > stage.canvas.width) { circle.x = 0; }
stage.addChild(circle);
stage.update();
}
document.addEventListener("mousemove", function(){circle.x = event.clientX,circle.y = event.clientY});
However when I try to include it in my function handleTick()
I get a thon of erros :
Uncaught TypeError: Cannot read property 'clientX' of undefined
Are there any other things I can use for this ? And why don't it work in my the handleTick()
function ?