Paper.js:用鼠标事件对受阻项目进行hitTest?

BKC*_*BKC 1 javascript hittest paperjs

我有两个项目,一个在另一个上,也就是说,一个挡住了另一个。假设 Item2 被 Item1 阻止。现在每当我使用

project.hitTest(Item2);
Run Code Online (Sandbox Code Playgroud)

效果很好。

但是当我使用鼠标的event.point时,就会出现问题。当我使用

project.hitTest(event.point);
Run Code Online (Sandbox Code Playgroud)

function onMouseUp(event){} 
Run Code Online (Sandbox Code Playgroud)

它只检测顶部的项目。是否可以检测所有项目?

Ale*_*olz 5

也许这会对您有所帮助:
http ://paperjs.org/reference/item/#contains-point

var path = new Path.Star({
center: [50, 50],
points: 12,
radius1: 20,
radius2: 40,
fillColor: 'black'
});

// Whenever the user presses the mouse:
function onMouseDown(event) {
// If the position of the mouse is within the path,
// set its fill color to red, otherwise set it to
// black:
if (path.contains(event.point)) {
    path.fillColor = 'red';
} else {
    path.fillColor = 'black';
}
}
Run Code Online (Sandbox Code Playgroud)

这不是最好的解决方案,因为你必须循环所有路径,但我现在不知道更好的解决方案。