Paperjs-无法清除光栅

问题描述 投票:0回答:1

我正在使用辅助功能绘制栅格:

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

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

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

谢谢您的帮助

javascript paperjs
1个回答
0
投票

[我认为您正在寻找item.remove()方法,该方法将项目从场景图中移走,从而使其消失。这是演示解决方案的sketch

// 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);
© www.soinside.com 2019 - 2024. All rights reserved.