@Varun_M wrote:
Hi,
I have upgraded my project from cocos2d-x v2.2 to v3.10. Since cocos2d-x v3.10 does not have the setTouchPriority function in the CCLayer class anymore, I had to make a function in my class to handle the touch priority. This is what I added:void PopupLayer::setTouchPriority(int priority) { Director::getInstance()->getEventDispatcher()->removeEventListenersForTarget(this); auto touchListener = EventListenerTouchOneByOne::create(); touchListener->onTouchBegan = CC_CALLBACK_2(PopupLayer::onTouchBegan, this); touchListener->onTouchEnded = CC_CALLBACK_2(PopupLayer::onTouchEnded, this); touchListener->onTouchMoved = CC_CALLBACK_2(PopupLayer::onTouchEnded, this); Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(touchListener, priority); }
The problem is that this doesn't seem to be working. I have the main layer of the game and when I try adding popup on top of it I want it to swallow the touch and prevent the main layer from being affected by the touch.
Instead, what's happening now is that the main layer can still be touched, and the popup layer on top of it cannot be touched. The main layer has a priority set to 4 and the priority of the popup layer is being set to 1.
Posts: 2
Participants: 2