I created a Layer, which has a sole purpose to block (“swallow”) touches, and this feature can be turned on and off.
The class is very basic, if it receives the touch it always swallows it:
bool BlockingLayer::init(){
// Super init.
if ( !CCLayer::init() )
{
return false;
}
setTouchEnabled(true);
setTouchMode(kCCTouchesOneByOne);
setTouchPriority(INT_MAX);
return true;
}
bool BlockingLayer::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
{
CCLOG(“BlockingLayer swallowed touch!”);
return true;
}
So by default it has a really bad priority, it receives touches if no other class claimed it. But in the scene where I am using this layer I would like to set it to a different priority when certain events occur:
bool MyScene::init(int unitNumber, CCString* path){
// Super init.
…
_blockingLayer = BlockingLayer::create();
this->addChild(_blockingLayer);
return true;
}
bool MyScene::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent){
_blockingLayer->setTouchPriority(INT_MIN);
}
Now the layer should have the best priority possible, so it should swallow all touches. But it does not, it’s behaviour does not change.
I see its registerWithTouchDispatcher() called and the m_nTouchPriority changed correctly. BUT the layer’s behaviour is unchanged.
This is on Cocos2D-x 2.2. Any help is appreciated.