My program recognizes the mousemove event
. What I would like to do is make my program work for mobile.
That is why I would like to transform the mousemove event to a touchmove event
.
My code is like this so far:
var d=ctx.getImageData(0,0,canvas.width,canvas.height).data;
$hit=$("#hit");
$("#canvas").mousemove(function(e){handleMouseMove(e);});
tolerance = 20;
function handleMouseMove(e){
e.preventDefault();
e.stopPropagation();
mouseX=parseInt(e.clientX-offsetX);
mouseY=parseInt(e.clientY-offsetY);
var isHit=d[(mouseY*cw+mouseX)*4+3]>tolerance;
if(isHit){
$hit.text("Yeahhhh");
}else{
//document.onmousemove = crash;
$hit.text("Noooooooo");
}
}
Is there a way that I can do that easily?
I have read that is equivalent When to use touchmove vs mousemove? but I am not sure how to handle the mouseX
and the mouseY
.