[ create a new paste ] login | about

Link: http://codepad.org/XH6E5sGg    [ raw code | fork ]

C, pasted on Sep 14:
<!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>


Create a new paste based on this one


Comments: