看了底层的代码你传的这个参数实质没什么影响。
你点cocos图标,应该会有两个节点响应分别是canvas、cocos
冒泡是在event-target.js里处理的
if (!event._propagationStopped && event.bubbles) {
// Event.BUBBLING_PHASE
owner._getBubblingTargets(event.type, cachedArray);
// propagate
event.eventPhase = 3;
......
}
断点可以看到mouse event的bubbles是false(应该是默认值,touch事件的也是在CCNode.js的_touchStartHandler赋值修改的),_propagationStopped是true (CCNode.js的_mouseDownHandler调用了一次stopPropagation),所以不会冒泡。
只要在需要冒泡的最顶层节点的响应函数里将这两个值赋值应该就可以冒泡了
this.node.on('mousedown', function (event) {
cc.log('current node: ' + event.getCurrentTarget().name + '--- button: ' + event.getButton());
event.bubbles = true
event._propagationStopped = false
}, this);
。。。我早就用这个办法改好了。。。只是这个方法不好。本身就是私有变量就是不想让你改了的。。。
除了黑科技,现在还可以先用 capture,也就是楼上神盾局大大的方法第四个参数填 true
在 1.7 会修复鼠标事件不能冒泡的问题
1赞
能把代码贴一下吗?小白刚开始学
我想问一下,为什么鼠标的监听事件 不好使呢,mac电脑,cocos creator 2.1
this.node.on(cc.Node.EventType.MOUSE_DOWN, function(){
console.log(“123123”);
}, this)
就是一个简单的监听,刚开始学,,,
