_onTouchEnd(touchEvent) { if (this.targetOfDragList.length === 0) { return; // 没有目标位置 } let inTarget = false; for (const targetNode ofthis.targetOfDragList) { if (this._withinTarget(targetNode, touchEvent)) { inTarget = true; break; } } if (!inTarget) { this.node.position = this._oldPos; // 回去 } }
// 判断触摸事件是否在槽位里 _withinTarget(targetNode: cc.Node, touchEvent) { let rect = targetNode.getBoundingBox(); let location = touchEvent.getLocation(); let point = targetNode.parent.convertToNodeSpaceAR(location); return rect.contains(point); } }