|
|
@@ -61,12 +61,33 @@ export default class GuideWeak extends cc.Component {
|
|
|
private onTouchStart(touch: cc.Touch, event: cc.Event.EventTouch): boolean {
|
|
|
// cc.log("touch start");
|
|
|
//此处必须返回true(表示接触到了节点),否则TOUCH_MOVE,TOUCH_END,TOUCH_CANCEL不触发。
|
|
|
- return true;
|
|
|
+ event.bubbles = true;
|
|
|
+ const point_world_pos = touch.getLocation();
|
|
|
+ let localPoint = this.node.parent.convertToNodeSpaceAR(new cc.Vec2(point_world_pos.x, point_world_pos.y));
|
|
|
+ let result = this.pointInPoly(localPoint, this.node);
|
|
|
+ return result;
|
|
|
}
|
|
|
private onTouchEnded(touch: cc.Touch, event: cc.Event.EventTouch): void {
|
|
|
// cc.log("touch end");
|
|
|
this.onClickCall(touch);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 点是否在节点宽高范围内
|
|
|
+ * @param point 点击的点
|
|
|
+ * @param node
|
|
|
+ * @returns
|
|
|
+ */
|
|
|
+ private pointInPoly(point: cc.Vec2 | cc.Vec3, node: cc.Node) {
|
|
|
+ const self_node_pos = node.getPosition();
|
|
|
+ if (point.x >= (self_node_pos.x - (this.node.width / 2)) &&
|
|
|
+ point.x <= (self_node_pos.x + (this.node.width / 2)) &&
|
|
|
+ point.y >= (self_node_pos.y - (this.node.height / 2)) &&
|
|
|
+ point.y <= (self_node_pos.y + (this.node.height / 2))) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
protected onDestroy(): void {
|
|
|
// super.onDestroy();
|
|
|
this._eventManager.removeListener(this._touchListener, this.node);
|