从 Paper.js 组中删除项目
Remove Item from Paper.js Group
Paper.js 有一个明确的方法可以将项目添加到 Group using addChild(item)
。但是,似乎没有明确的方法可以在不从视图中删除项目本身的情况下从组中删除项目。
组有一个 children
属性,但根据文档,它不应该被改变:
The children array should not be modified directly using array functions. To remove single items from the children list, use item.remove(), to remove all items from the children list, use item.removeChildren(). To add items to the children list, use item.addChild(item) or item.insertChild(index, item).
所以每个项目都有一个 remove()
方法,但这不仅将其从组中删除,而且从显示中删除。
如何从组中删除项目,仅将其与组取消关联而不将其从显示中删除?有比这更简洁的方法吗?
item.remove();
paper.project.activeLayer.addChild(item);
你的方法
item.remove();
paper.project.activeLayer.addChild(item);
应该怎么做。除非你调用 paper.view.update() 它不会在两次调用之间重新渲染 canvas,所以进行额外的函数调用几乎没有成本。
Paper.js 有一个明确的方法可以将项目添加到 Group using addChild(item)
。但是,似乎没有明确的方法可以在不从视图中删除项目本身的情况下从组中删除项目。
组有一个 children
属性,但根据文档,它不应该被改变:
The children array should not be modified directly using array functions. To remove single items from the children list, use item.remove(), to remove all items from the children list, use item.removeChildren(). To add items to the children list, use item.addChild(item) or item.insertChild(index, item).
所以每个项目都有一个 remove()
方法,但这不仅将其从组中删除,而且从显示中删除。
如何从组中删除项目,仅将其与组取消关联而不将其从显示中删除?有比这更简洁的方法吗?
item.remove();
paper.project.activeLayer.addChild(item);
你的方法
item.remove();
paper.project.activeLayer.addChild(item);
应该怎么做。除非你调用 paper.view.update() 它不会在两次调用之间重新渲染 canvas,所以进行额外的函数调用几乎没有成本。