Touching menu item does't call my callback function?

I try to mimic the “tests” menu in controller.cpp from cocos2dx example.

———————- My code to render the menu ——————————————

CCMenu itemMenu = CCMenu::menuWithItems;
for{
CCLabelTTF
label = CCLabelTTF::labelWithString(“KKKK”,“Arial”,24);
label~~>setColor);
label~~>setPosition(ccp(150,150+i*150));
CCMenuItemLabel *menuItem = CCMenuItemLabel::itemWithLabel(label,this,menu_selector(MainMenuLayer::menuCallback));
itemMenu~~>addChild;
}
itemMenu~~>setContentSize(CCSizeMake(screenSize.width/2,500));
itemMenu->setPosition(ccp(150,150));
setIsTouchEnabled(true);
addChild(itemMenu);

————————— my callback function ————————————————
void MainMenuLayer::menuCallback(CCNode* sender){
CCLog(“[DEBUG] menuCallback”);

}

The execution shows the right effect what i expect (two item named “KKK”).

However, when I pressed the “KKKK” label, cocos2dx doesn’t call my callback function?(I don’t receive the logcat msg)

Can anyone help me? thanks

I think you should set position by CCMenuItemLabel, not CCLabelTTF.
So I think your codes should be changed to

CCMenu *itemMenu = CCMenu::menuWithItems(NULL);
        for(int i=0;i<2;i++){
        CCLabelTTF *label = CCLabelTTF::labelWithString("KKKK","Arial",24);
                label->setColor(ccc3(0,0,0));
                //label->setPosition(ccp(150,150+i*150));
                CCMenuItemLabel *menuItem = CCMenuItemLabel::itemWithLabel(label,this,menu_selector(MainMenuLayer::menuCallback));
                menuItem->setPosition(ccp(150,150+i*150)); // set position by CCMenuItemLabel
                itemMenu->addChild(menuItem,5);
        }
        itemMenu->setContentSize(CCSizeMake(screenSize.width/2,500));
        itemMenu->setPosition(ccp(150,150));
        setIsTouchEnabled(true);
        addChild(itemMenu);

And I run the test project on Android 2.2&3.2 ,the menu does not action.

Thanks, Minggo!

You are right, setting the item’s position rather than label’s position solves this problem!

Minggo n1. Thank you (/)