Use the following for mouse movement:
window.addEventListener("mousemove", function(e)
{
{
// offsetX and layerX are actual positons of the canvas, while clientX is the position
in the page
// in the page
mouse.x = e.offsetX || e.layerX;
mouse.y = e.offsetY || e.layerY;
// detect a mouse click here
updateCanvasForClick();
});
You can also round the position to get the tile:
function getTile(canvasX, canvasY)
{
var x = updateCanvasForClickMath.floor(canvasX / tileWidth);
}var y = Math.floor(canvasY / tileHeight);
return map[x][y];
}