The priority of Event Response and stopprogapation disable the response of lower-level components.

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.