最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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();
});
发布评论

评论列表(0)

  1. 暂无评论