-
Creator 版本: 2.3.0
-
目标平台: Web/小游戏
使用
this.node..on(cc.Node.EventType.MOUSE_DOWN, this.touchTarget, this);
注册监听, 在节点后面的button能够再次接收到事件(符合预期)但是 如果换成
this.node.on(cc.Node.EventType.TOUCH_START, this.touchTarget, this);
就不行了,
这是啥原因呢?
Creator 版本: 2.3.0
目标平台: Web/小游戏
使用
this.node..on(cc.Node.EventType.MOUSE_DOWN, this.touchTarget, this);
注册监听, 在节点后面的button能够再次接收到事件(符合预期)但是 如果换成
this.node.on(cc.Node.EventType.TOUCH_START, this.touchTarget, this);
就不行了,
这是啥原因呢?
测试方法,创建两个sprite, 前红后绿
分别挂上下面的脚本
const {ccclass, property} = cc._decorator;
@ccclass
export default class TestTouchThrough extends cc.Component {
onLoad(){
this.node.on(cc.Node.EventType.MOUSE_DOWN, ()=>{cc.log("touching " + this.node.name)},this);
}
// update (dt) {}
}
在浏览器里面点击红色的块儿,会打印两句话,如果把MOUSE_DOWN换成TOUCH_START就只有前面红色方框的上监听打印了。
哎呀,
this.node.on(cc.Node.EventType.TOUCH_START, ()=>{cc.log("touching " + this.node.name)},this);
if(this.node["_touchListener"] != null){
this.node["_touchListener"].swallowTouches = false;
}
cc.log(this.node);
这样解决了,但是感觉这个地方应该好好弄一下,默认就穿了(跟MOUSE_DOWN一样)比较好?