I have two odd problems with fillright (x, y, width, height).
This code is from a video tutorial, and this code seems to work for the guy and the video, and everyone else, since no one has commented on this problem. Anyway, here is the code:
function doFirst(){ canv = document.getElementById('canvas'); canvas = canv.getContext('2d'); document.addEventListener("mousemove", onMouseMove, false); } function onMouseMove(e){ canvas.clearRect(0, 0, canv.width, canv.height); var x = e.clientX; var y = e.clientY; canvas.fillRect(x, y, 50, 50); } window.addEventListener("load", doFirst, false);
I thought that maybe I skipped a step in the tutorial, and after checking again and again, I decided to simplify it by just drawing a rectangle without a mouse listener, but the canvas still painted it with a height of 2X and about 2x y position.
function doFirst(){ canv = document.getElementById('canvas'); canvas = canv.getContext('2d'); canvas.fillRect(10, 10, 50, 50); } window.addEventListener("load", doFirst, false);
The fillRect function only worked fine the other day when I first started playing with an HTML5 canvas, so what happened? how did i break it?