android - CCLayer setTouchPriority has no effect -
i created layer, has sole purpose block ("swallow") touches, , feature can turned on , off. class basic, if receives touch 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 default has bad priority, receives touches if no other class claimed it. in scene using layer set different priority when 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 layer should have best priority possible, should swallow touches. not, behaviour not change. see registerwithtouchdispatcher() called , m_ntouchpriority changed correctly. layer's behaviour unchanged.
this on cocos2d-x 2.2. appreciated.
in addtargeteddelegate() set third param true
bool blockinglayer::init(){ // super init. if ( !cclayer::init() ) { return false; } settouchenabled(true); settouchmode(kcctouchesonebyone); settouchpriority(int_max); return true; } void blockinglayer::onenter() { ccdirector::shareddirector()->gettouchdispatcher()->addtargeteddelegate(this, int_max, true); //<---- param (target, touchpriority, isswallowtouches ) ccnode::onenter(); } void blockinglayer::onexit() { ccdirector::shareddirector()->gettouchdispatcher()->removedelegate( ); ccnode::onexit(); } bool blockinglayer::cctouchbegan(cctouch *ptouch, ccevent *pevent) { cclog("blockinglayer swallowed touch!"); return true; }
Comments
Post a Comment