with newer paper.js version one direct way to get all Items is to use hitTestAll()
:
Performs a hit-test on the item and its children (if it is a Group or Layer) at the location of the specified point, returning all found hits.
example:
var hitOptions = {
segments: true,
stroke: true,
fill: true,
tolerance: 5,
};
function onMouseUp(event) {
console.log('******************************************');
var hitResult = project.hitTestAll(event.point, hitOptions);
console.log('hitResult (' + hitResult.length + ')' , hitResult);
if (hitResult) {
// do something...
}
}
alternative you can try to use the normal hitTest()
with an options.match
filter function.
example2 - only returns a hit result if the bottom-most object is hit:
function hitMatchFilter(hitResult) {
//console.log('hitMatchFilter:', hitResult);
let flag_obj_is_first = false;
if (hitResult.item) {
let hititem = hitResult.item;
if (hititem.parent.children[0] == hititem) {
//console.log('hititem isFirst in parent child list');
flag_obj_is_first = true;
}
}
return flag_obj_is_first;
}
var hitOptions = {
segments: true,
stroke: true,
fill: true,
tolerance: 5,
match: hitMatchFilter,
};
function onMouseUp(event) {
console.log('******************************************');
var hitResult = project.hitTest(event.point, hitOptions);
console.log('hitResult', hitResult);
if (hitResult) {
// do something...
}
}