EricPinxteren Posted October 6, 2011 Share Posted October 6, 2011 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: <!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 Link to comment Share on other sites More sharing options...
justsomeguy Posted October 6, 2011 Share Posted October 6, 2011 It sounds like the area you're clearing isn't large enough. Link to comment Share on other sites More sharing options...
EricPinxteren Posted October 6, 2011 Author Share Posted October 6, 2011 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 More sharing options...
justsomeguy Posted October 6, 2011 Share Posted October 6, 2011 Have you tried using integer values for f? Link to comment Share on other sites More sharing options...
EricPinxteren Posted October 6, 2011 Author Share Posted October 6, 2011 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 More sharing options...
justsomeguy Posted October 6, 2011 Share Posted October 6, 2011 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 More sharing options...
EricPinxteren Posted October 6, 2011 Author Share Posted October 6, 2011 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.