I have a Html 5 Canvas what takes up 100% of the width and 90% of the height (the top 90%) of the screen. Im trying to make an eraser that as a user touches and drags it makes anything on the canvas transparent. The problem is the "eraser" is about 20-30px lower than the users finger when they touch. Ive experimented around but it isn't changing. Any ideas?
var canvas=document.getElementById("viewport"); // grabs the canvas element
var context=canvas.getContext("2d"); // returns the 2d context object
canvas.addEventListener("touchmove", function (e) {
e.preventDefault();
drawPoint(e.touches[0].screenX - canvas.offsetLeft, e.touches[0].screenY - canvas.offsetTop);
}, false);
function drawPoint(x, y) {
var canvas=document.getElementById("viewport"); // grabs the canvas element
var context=canvas.getContext("2d"); // returns the 2d context object
context.fillStyle = "rgba(0,0,0,1)"; // (Drawing with 0 alpha pretty much means doing nothing)
context.globalCompositeOperation = "destination-out";
context.beginPath();
context.arc(x, y, 10, 0, Math.PI * 2, true);
context.fill();
context.closePath();
}