javascript - Konva - clear layer but keep the background - Stack Overflow

Im trying to clear the layer from every circle and line (remove it pletely) but keep the image in the b

Im trying to clear the layer from every circle and line (remove it pletely) but keep the image in the background.

If I use layer.clear() it removes the image also.

Question: How to clear the layer but avoid removing the image?

Im trying to clear the layer from every circle and line (remove it pletely) but keep the image in the background.

If I use layer.clear() it removes the image also.

Question: How to clear the layer but avoid removing the image?

https://codesandbox.io/s/sharp-night-t4vtt

Share Improve this question asked Sep 3, 2019 at 10:18 PatrickkxPatrickkx 1,8809 gold badges38 silver badges66 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

layer.clear() do not remove objects from the scene. It is just clear canvas element and on the next layer.draw() all objects will be drawn again.

Instead of layer.clear() you need to remove objects, that you don't need anymore. From the demo, I see that you need to remove lines and circles. You can use layer.find(selector) to find that nodes and destroy them.

document.getElementById("btn").addEventListener("click", () => {
  layer.find('Line').destroy();
  layer.find('Circle').destroy();
  layer.draw();
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745246559a4618436.html

相关推荐

  • javascript - Konva - clear layer but keep the background - Stack Overflow

    Im trying to clear the layer from every circle and line (remove it pletely) but keep the image in the b

    7小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信