首页 > 解决方案 > Paperjs - 无法清除光栅

问题描述

我正在使用辅助函数绘制栅格,如下所示:

 const icon = new Raster({
 source: getBase64Icon(source,
    position: new Point(x, y)
 });
 icon.scale(scale);

它确实有效,我在正确的位置以正确的比例获得了图标。问题是当我尝试使用该clear()方法清除栅格时。我什至尝试icon.clear();在缩放后显式添加,但它不起作用。没有错误,并且登录到控制台icon.clear确实显示了功能代码。

也许重要的是要提到这些图标是在特定图层上绘制的。

谢谢您的帮助

标签: javascriptpaperjs

解决方案


我认为您正在寻找item.remove()将项目从场景图中取出并使其消失的方法。
这是演示解决方案的草图。

// Draw an image.
const raster = new Raster({
    source: 'http://assets.paperjs.org/images/marilyn.jpg',
    position: view.center
});

// Wait 4 seconds...
setTimeout(() => {
    // ...then remove it.
    raster.remove();
}, 4000);

推荐阅读