如何从PaperJS中的CompoundPath识别鼠标事件的目标子路径?

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

我将'mousedown'事件侦听器添加到CompoundPath(而不是其子对象)。但是我需要知道事件发生在哪个孩子身上。事件对象的'target'属性将返回CompoundPath。那么,解决方案是什么?

javascript paperjs
1个回答
0
投票
const circle1 = new Path.Circle({ center: view.center - 50, radius: 50 }); const circle2 = new Path.Circle({ center: view.center + 50, radius: 50 }); const compoundPath = new CompoundPath({ children: [circle1, circle2], fillColor: 'orange', onMouseDown: event => { if (circle1.hitTest(event.point)) { alert('circle 1 clicked'); } else if (circle2.hitTest(event.point)) { alert('circle 2 clicked'); } } });
© www.soinside.com 2019 - 2024. All rights reserved.