clearRect does not clear the canvas when drawing vertical lines

前端 未结 1 1409
半阙折子戏
半阙折子戏 2020-12-10 12:44

I hit a weird edge case building something with canvas at work. clearRect does not clear the canvas when drawing vertical lines that go from the top to the bottom of the can

相关标签:
1条回答
  • 2020-12-10 13:41

    Your issue is with a missing beginPath causing subsequent lines to be added to the same path that was stroke drawing all lines.

    If you switch to dots and back to lines with the clearRect option choose you can see the last arc added to the path being drawn too. Just add a call ctx.beginPath(); prior ctx.moveTo(randomX + 0.5, 0); ctx.lineTo(randomX + 0.5, canvas.height); and the problem is solved.

    You can check http://jsfiddle.net/kZj6F/1/ to see it working.

    Bwt it will with other shapes too if they got added to the path and the path was not cleared.

    0 讨论(0)
提交回复
热议问题