0
votes

I am clearing canvas using ctx.clearRect(0,0,canvas.width,canvas.height) and just for debug I redraw after 2 seconds, on second time I redraw all content instead of lines. but it still showing one line on canvas which I draw lastly.

1
As a long shot i wonder if you didn't miss a beginPath. Please take some time to better explain your goal / issue. - GameAlchemist

1 Answers

0
votes

I have had problems before clearing a canvas by creating a full sized rectangle, so instead I use this more effective approach you may find helpful:

function clearCanvas(){
    var context = canvas.getContext("2d");
    context.clearRect(0, 0, canvas.width, canvas.height); //default
    var w = canvas.width;
    canvas.width = 1;
    canvas.width = w; //Also change and re-apply canvas width
    return;
}

Would you be able to post your full code?