Jump to content

Html 5 Canvas Clearrect Prob. (Go Away Rect! )


EricPinxteren

Recommended Posts

Hi all, I'm working on a problom with canvas.. i just can's get it the work. I want to clear a rect of pixels, but there are stil some pixels left.. See for youre self: go away.GIF

<!DOCTYPE html><html><body><canvas id="myCanvas" width="500" height="500" style="border:1px solid #c3c3c3;">Your browser does not support the canvas element.</canvas><script type="text/javascript">var c=document.getElementById("myCanvas");var cxt=c.getContext("2d");var f = 80.6;var x = 10;var y = 30;//Try 1 		    cxt.fillStyle = 'RED';		    cxt.fillRect (x,y,f,f);			    cxt.clearRect(x,y,f,f); //Go Away!//Try 2 x += f+5; f = 90.3;		    cxt.fillStyle = 'BLUE';		    cxt.fillRect (x,y,f,f);			    cxt.clearRect(x,y,f,f); //Go Away!//Try 3x += f+5;f = 100.5;		    cxt.fillStyle = 'GRAY';		    cxt.fillRect (x,y,f,f);			    cxt.fillStyle = 'WHITE'; 		    cxt.fillRect (x,y,f,f); //Go Away!, it's not clear i just paint over it.. and it stil does not work!								    //The clearRect method clears the canvas to transparent black.  i want that//Try 4x += f+5; f = 150.6;		    cxt.fillStyle = 'RED';		    cxt.beginPath(); 		    cxt.rect(x,y,f,f);			    cxt.fill();			    cxt.clearRect(x,y,f,f); //Go Away!   </script></body></html>

goAway.htm

post-85096-0-34813200-1317895633_thumb.gif

Link to comment
Share on other sites

It sounds like the area you're clearing isn't large enough.
Thanks for replying, but In all my 4 examples i draw en clear a rectangle with the same width,height (in example the var 'f'). In 'try 3' i try to overwrite it with "white" rectangle , not really clear but the previous rectangle color still stay visible on the border..
Link to comment
Share on other sites

Have you tried using integer values for f?
Yes that works, only the pixels can be doubles. See the HTML standard: void clearRect(double x, double y, double w, double h); void fillRect(double x, double y, double w, double h); http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.htmlit's very critecle for my application that i can clear a rectangle where i draw-ed it You can see the difference of a rectangle(w,h) of (0.1,0.1) and (1,1).
Link to comment
Share on other sites

It sounds like an issue with the canvas implementation. You may need to use something other than canvas if you need to use fractional positions. Different browsers may handle it differently. If it works with integers but not doubles then it sounds like a problem in the browser.

Link to comment
Share on other sites

It sounds like an issue with the canvas implementation. You may need to use something other than canvas if you need to use fractional positions. Different browsers may handle it differently. If it works with integers but not doubles then it sounds like a problem in the browser.
Thanks for the help anyway.. i need canvas. my only option ;) i do a work around.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...