|
- function 事件穿透(e, currentObject) {
- // 获取全局点击坐标
- const globalX = e.global.x;
- const globalY = e.global.y;
-
- // 找出所有在点击位置下的交互对象
- // 遍历舞台的所有子元素(跳过当前对象自身)
- app.stage.children.forEach(child => {
- // 跳过当前对象和非交互对象
- if (child === currentObject || !child.interactive) return;
-
- // 检查点击是否在这个对象的区域内
- // 注意:这里假设所有对象都是矩形,复杂形状可能需要更复杂的碰撞检测
- if (child.getBounds) {
- const bounds = child.getBounds();
- if (globalX >= bounds.x && globalX <= bounds.x + bounds.width &&
- globalY >= bounds.y && globalY <= bounds.y + bounds.height) {
- // 手动触发这个对象的事件
- child.emit('pointerdown', e);
- }
- }
- });
- }
复制代码
|
|