HTML5 Canvas slows down with each stroke and clear

后端 未结 1 1424
[愿得一人]
[愿得一人] 2020-12-01 11:40

I\'ve been playing around with the HTML5 Canvas and I\'ve noticed something that I couldn\'t find a resolution for online. Here\'s the simple code I\'m playing with

相关标签:
1条回答
  • 2020-12-01 12:04

    The <canvas> element keeps track of a current path (i.e., set of points, lines, and curves). canvas.moveTo, canvas.lineTo, and canvas.stroke all operate on the current path. Every time you call canvas.moveTo or canvas.lineTo you are adding to the current path. As the path gets more and more complex, drawing gets slower and slower.

    You can clear the path by calling canvas.beginPath(). Doing this at the start of your draw function should get rid of the slowdown.

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