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.
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); |
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){} |