Erasing previously drawn lines on an HTML5 canvas

后端 未结 5 1656
臣服心动
臣服心动 2020-12-03 07:36

To play around with HTML5 canvas, I decided to make an app which draws an analogue clockface. Everything\'s fine, except that old lines don\'t get erased in the way that I w

5条回答
  •  失恋的感觉
    2020-12-03 08:00

    For reasons that I could expand upon, you should consider clearing your canvas and redrawing it entirely unless there are performance or compositing reasons not to.

    You want clearRect, something like this:

    //clear the canvas so we can draw a fresh clock
    ctx.clearRect(0, 0, canvasWidth, canvasHeight);
    
    //redraw your clock here
    /* ... */
    

提交回复
热议问题