Search code examples
ioscanvashtml5-canvaskineticjskonvajs

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


In KonvaJS defining sceneFunc() for any Shape will result in calling it each time draw() is called,

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

The question is: How to prevent sceneFunc() from clearing the context and persist the past drawings on the previous call of it?


Solution

  • You can use clearBeforeDraw property:

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

    From docs:

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