COCOS2D-JS Tutorial Cocos2d-js occlusion Layer (disable Touch Event pass layer)

Source: Internet
Author: User

In the game, we often encounter some pop-up window, these pop-up window to prohibit the point through, that is, prohibit the touch event to the bottom, we call the occlusion layer, these occlusion layer, need to develop the occlusion layer, we must first understand the COCOS2D-JS touch transfer mechanism, this article mainly for Cocos2d-js v3.0 Final version.

According to the official documentation, we know that there are five ways to touch, but according to the requirements, we need to do is to intercept the touch monitoring.

So we simply encapsulate such a class as follows:

Acl Modellayercolor =cc. Layercolor.extend ({m_touchlistener:NULL, ctor:function(){     This. _super (); varTouchlistener ={event:cc. Eventlistener.touch_one_by_one, Swallowtouches:true, Ontouchbegan: This. Ontouchbegan}; Cc.eventManager.addListener (Touchlistener, This);  This. M_touchlistener =Touchlistener; }, Ontouchbegan:function(Touch, event) {vartarget =Event.getcurrenttarget (); if(!target.isvisible () | | (! This. Istouchinside (Target,touch))) {      return false; }    return true; }, Istouchinside:function(Owner,touch) {if(!owner | |!owner.getparent ()) {      return false; }    varTouchlocation = Touch.getlocation ();//Get the touch positionTouchlocation =owner.getparent (). Converttonodespace (touchlocation); returnCc.rectcontainspoint (Owner.getboundingbox (), touchlocation); }});
This is to set the swallowtouches to true so that Ontouchbegan returns true to devour the touch without continuing to pass to the lower priority layer to implement the occlusion layer.

COCOS2D-JS Tutorial Cocos2d-js occlusion Layer (disable Touch Event pass layer)

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.