<!DOCTYPE html>
<head>
<title>Canvas Test</title>
</head>
<body>
<canvas id="canvas" width="640" height="480"></canvas>
</body>
<script>
function draw(h, ctx)
{
ctx.fillRect(h.x, h.y, h.w, h.h);
}
var cx, cy;
var player = { x: 0, y: 0, w: 85, h: 60 };
var ctx = document.querySelector("canvas").getContext("2d");
document.onmousemove = function(e) {
cx = e.pageX;
cy = e.pageY;
}
document.body.onmousedown = function() {
player.x = cx;
player.y = cy;
}
draw(player, ctx);
</script>
</html>