Touch delegate Priority Problem

Hi,
I wanted to create a pop up dialog effect. And 1st thing about pop up is that it should block all touch events.
So i created a DecoyLayerForDialog that blocks all the touch events by returning true in ccTouchBegin and set the priority to kCCMenuHandlerPriority - 1 so that the touch event for menu in the dialog wont be blocked.

#include "DecoyLayerForDialog.h"

bool DecoyLayerForDialog::init(){
    do{
        CC_BREAK_IF( !CCLayer::init() );

        cocos2d::CCSize winSize = cocos2d::CCDirector::sharedDirector()->getWinSize();

        CCLayerColor *bg = CCLayerColor::layerWithColor( ccc4(0,0,0, 100), winSize.width, winSize.height );
        this->addChild(bg);

        CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, kCCMenuHandlerPriority - 1 , true);

        return true;
    }while(0);
    return false;
}



bool DecoyLayerForDialog::ccTouchBegan(cocos2d::CCTouch *pTouch,cocos2d::CCEvent *pEvent){
    return true;
}

void DecoyLayerForDialog::ccTouchMoved(cocos2d::CCTouch *pTouch,cocos2d::CCEvent *pEvent){

}

void DecoyLayerForDialog::ccTouchEnded(cocos2d::CCTouch *pTouch,cocos2d::CCEvent *pEvent){

}

In the showDialog function I created a DecoyLayerForDialog .
Now I created anther layer called DialogLayer on which i’ll add all the content to be shown and CCMenu attached to it.
i added both layers according to z-index.

void DialogFactory::showDialog( _DIALOG_TYPE_ dialogType, SEL_MenuHandler selector ){
    DecoyLayerForDialog *decoy = DecoyLayerForDialog::create();
    CCLayer *dialog = CCLayer::create();

    CCScene *currentScene = CCDirector::sharedDirector()->getRunningScene();

    cocos2d::CCMenuItemFont *pOkButton = cocos2d::CCMenuItemFont::itemWithString("Exit", dialog, selector);
    CCMenu *pMenu = CCMenu::menuWithItem(pOkButton);
    dialog->addChild(pMenu, 100002);

    currentScene->addChild(decoy, 100000);
    currentScene->addChild(dialog, 100001);
}

But the CCMenu i attached to dialog layer is not working.
If i return false in DecoyLayerForDialog then menu in dialog works but the menu under the decoy layer also became tapable.
How to prioritize the touch delegates and make it swallow the event??

Here is the pictorial representation of the model I made.

If you have CCDirector::sharedDirector()->getTouchDispatcher()>addTargetedDelegate; for your DecoyLayerForDialog then you should also change priority of CCMenu on DialogLayer to lower than for example with ccmenuobject>setHandlerPriority(kCCMenuHandlerPriority - 2); Then this menu should be able to capture touches.

I am having this same problem, so I tried what you suggested.

I have a CCLayer that is registered with Touch Dispatcher as:

cocos2d::CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this,
                                                                        cocos2d::kCCMenuHandlerPriority - 1, true);

I have a CCMenu added to this layer and it is not receiving events.

I tried doing:

pHUDMenu = cocos2d::CCMenu::createWithArray(pHUDMenuItems);

        CC_BREAK_IF(!pHUDMenu);

        pHUDMenu->setHandlerPriority((cocos2d::kCCMenuHandlerPriority - 2));

But I am getting an assertion failure in:

void CCTouchDispatcher::setPriority(int nPriority, CCTouchDelegate *pDelegate)
{
    CCAssert(pDelegate != NULL, "");

    CCTouchHandler *handler = NULL;

    handler = this->findHandler(pDelegate);

    CCAssert(handler != NULL, "");

    if (handler->getPriority() != nPriority)
    {
        handler->setPriority(nPriority);
        this->rearrangeHandlers(m_pTargetedHandlers);
        this->rearrangeHandlers(m_pStandardHandlers);
    }
}

That is:

Assertion failed: (handler != __null), function setPriority, file /Users/jtsm/Projects/_libs/cocos2dx/touch_dispatcher/CCTouchDispatcher.cpp, line 306.

Can anyone explain my error?

Interesting I’m in the same trouble.
Did someone solved it in 9 months?