cocos2dx 玩转多子菜单回调

前端之家收集整理的这篇文章主要介绍了cocos2dx 玩转多子菜单回调前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
std::string items[] = {"1","2","3,"4","5","6","7","8","9"};

CCMenu * m_pItmeMenu = CCMenu::create();
CCSize size = CCDirector::sharedDirector()->getWinSize();
int m_nTestCount = sizeof(items) / sizeof(items[0]);
for (int i = 0; i<=m_nTestCount ;i++)
{
    LabelTTF * label = LabelTTF::create(items[i].c_str(),"",20);
    label->setColor(Color3B::GREEN);
    MenuItemLabel * pMenuItem = MenuItemLabel::create(label,CC_CALLBACK_1(HelloWorld::menuBack,this));
    m_pItmeMenu->addChild(pMenuItem,i);//i 是回调关键
    pMenuItem->setPosition(CCPointMake(0,(size.height*0.5  - (i + 1) * 30)));
}
addChild(m_pItmeMenu,0,100);

回调函数

void HelloWorld::menuBack(Ref * pSender)
{

    MenuItem * pMenuItem = (MenuItem *)(pSender);
    int nIdx = pMenuItem->getZOrder();
}

猜你在找的Cocos2d-x相关文章