触摸事件接收不到

mukeywala
Thu, 10 May 2018 06:56:33 +0000

解决：
在touchCancel里发送事件到content 的子节点:
`
this.touchToCancel.on(cc.Node.EventType.TOUCH_END, function(event){
// 如果存在该直接点
let endEvent = new cc.Event.EventTouch(event.getTouches(), true);
endEvent.type = cc.Node.EventType.TOUCH_END;
endEvent.touch = event.touch;
endEvent.simulate = true;
this.content.child1.dispatchEvent(endEvent);

    //等待content 的子节点触摸返回是否点了child1，如果没有点击继续执行原有逻辑，点击了就直接返回
});

在content 的子节点里接收事件:
child1.on(cc.Node.EventType.TOUCH_END, function(event) {
let touches = event.getTouches();
let touchLoc = touches[0].getLocation();
let locationInNode = this.bg.convertToNodeSpace(touchLoc);
let s = this.bg.getContentSize();
let rect = cc.rect(0, 0, s.width, s.height);

    if (cc.rectContainsPoint(rect, locationInNode)) {
        // do something ...
        // 返回 touchCancel 我点击了
    }
}.bind(this));

`

阅读整个主题