如何防止 sceneFunc() 每次都清除上下文?

How to prevent sceneFunc() from clearing the context each time?

KonvaJS 中为任何 Shape 定义 sceneFunc() 将导致每次调用 draw() 时调用它,

  1. Shape.draw()
  2. layer.draw()
  3. stage.draw()

问题是:如何防止sceneFunc()清除上下文并在上一次调用它时保留过去的图纸?

您可以使用 clearBeforeDraw 属性:

var layer = new Konva.Layer({clearBeforeDraw: false});

来自文档:

set this property to false if you don't want to clear the canvas before each layer draw. The default value is true.