Cocos2d-js has no complete mouse event processing, this is worse than JS/flash, but it can also be used together. In general interface programming, you can use the node in the display list as the priority of the listener. The node at the top is higher than the node at the bottom. While the cocos2d-js does not stopimmediatepropagation, only stopprogapation, once a listener executes stopprogapation, subsequent listeners will not be executed. There is no bubble concept in JS/flash. If stopprogapation is enabled in the upper node, the effect is a bit like swallowtouches: True, but it is more flexible. For example, two sprite instances are added on the interface, where Child1 is located, and child2 is on. The following code indicates that the listener of child2 has a high priority and will be executed first. func2 will output the listener first because it is executed in order. However, the listener of Child1 will not be executed due to stopprogapation.
If ("touches" in CC. SYS. capabilities) {CC. eventmanager. addlistener ({event: CC. eventlistener. touch_one_by_one, ontouchbegan: function () {trace ("func1"); Return true ;}, this. child1); CC. eventmanager. addlistener ({event: CC. eventlistener. touch_one_by_one, ontouchbegan: function (touch, event) {trace ("func2"); // execute in sequence. First func2, then func3 return true ;}, this. child2); CC. eventmanager. addlistener ({event: CC. eventlistener. touch_one_by_one, ontouchbegan: function (touch, event) {trace ("func3"); event. stoppropagation (); Return true ;}}, this. child2);} else {CC. eventmanager. addlistener ({event: CC. eventlistener. mouse, onmousedown: function () {trace ("func1") ;}}, this. child1); CC. eventmanager. addlistener ({event: CC. eventlistener. mouse, onmousedown: function (event) {trace ("func2"); // execute in order, first func2, then func3}, this. child2); CC. eventmanager. addlistener ({event: CC. eventlistener. mouse, onmousedown: function (event) {trace ("func3"); event. stoppropagation () ;}}, this. child2 );}
The priority of Event Response and stopprogapation disable the response of lower-level components.