Cocos2dx shielding layer

Source: Internet
Author: User

Cocos2dx shielding layer

This is often the case when we are designing games with cocos2d-x Engines

We need to create A layer A that overwrites layer B. When we perform A touch operation on Layer A, we may perform operations on layer B. So what we need to do is

When layer A overwrites layer B, the touch event of screen B


From an article

Layer Shields touch events

There is a problem here. When you touch on the popLayer layer, you will find that the underlying GameScene will respond. In this case, you need to block the touch event processing for popLayer and should not pass it to the underlying layer.

  1. Register touch event listening in inin Method

    12345678 // Set the touch event listenerauto touchListener = EventListenerTouchOneByOne::create();touchListener->onTouchBegan = CC_CALLBACK_2(PopLayer::onTouchBegan, this);touchListener->onTouchMoved = CC_CALLBACK_2(PopLayer::onTouchMoved, this);touchListener->onTouchEnded = CC_CALLBACK_2(PopLayer::onTouchEnded, this);_eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener,this);// Set whether the event is swallowed up. If the onTouchBegan method returns true, the event is swallowed up.touchListener->setSwallowTouches(true);
  2. Empty listener function for touch events

    12345678910 boolGameOverLayer::onTouchBegan(Touch* touch, Event* event){returntrue;}voidGameOverLayer::onTouchMoved(Touch* touch, Event* event){}voidGameOverLayer::onTouchEnded(Touch* touch, Event* event){}

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.