请帮帮我,我是cocos2d-x的初学者。我有单子上的东西。如何使用项目数组完成此操作,使用CCMenu::createWithArray在末尾显示此列表?我想控制菜单数组,从数组中添加/删除项目(从我的列表菜单)。
代码如下:
...
CCLabelTTF* pp0BtnLabel = CCLabelTTF::create( string(ItemName[0]).c_str(), "Arial", TITLE_FONT_SIZE);
CCMenuItemLabel *pp0Item = CCMenuItemLabel::create(
pp0BtnLabel,
this,
menu_selector(Window::CheckItemCallback));
pp0Item->setTag(ItemTag[0]);
CC_BREAK_IF(! pp0Item);
pp0Item->setPosition(ccp(size.width*0.3f, size.height*0.8));
CCLabelTTF* pp1BtnLabel = CCLabelTTF::create( string(ItemName[0]).c_str(), "Arial", TITLE_FONT_SIZE);
CCMenuItemLabel *pp1Item = CCMenuItemLabel::create(
pp1BtnLabel,
this,
menu_selector(Window::CheckItemCallback));
pp1Item->setTag(ItemTag[0]);
CC_BREAK_IF(! pp1Item);
pp1Item->setPosition(ccp(size.width*0.3f, size.height*0.75));
CCLabelTTF* pp2BtnLabel = CCLabelTTF::create( string(ItemName[0]).c_str(), "Arial", TITLE_FONT_SIZE);
CCMenuItemLabel *pp2Item = CCMenuItemLabel::create(
pp2BtnLabel,
this,
menu_selector(Window::CheckItemCallback));
pp2Item->setTag(ItemTag[0]);
CC_BREAK_IF(! pp2Item);
pp2Item->setPosition(ccp(size.width*0.3f, size.height*0.7));
CCMenu* pMenuChapter = CCMenu::create(pp0Item, pp1Item, pp2Item, NULL);
pMenuChapter->setPosition(CCPointZero);
CC_BREAK_IF(! pMenuChapter);
this->addChild(pMenuChapter, 1);
...发布于 2013-02-16 16:05:24
我不太明白你的问题。但下面是使用CCArray创建CCMenu的方法。
CCLabelTTF*label = CCLabelTTF::create("label text", "Arial", 32);
CCMenuItemLabel *item1 = CCMenuItemLabel::create(label, this, menu_selector(CPhysicsLayer::itemCallback));
CCMenuItemLabel *item2 = CCMenuItemLabel::create(label, this, menu_selector(CPhysicsLayer::itemCallback));
CCMenuItemLabel *item3 = CCMenuItemLabel::create(label, this, menu_selector(CPhysicsLayer::itemCallback));
CCArray*array = CCArray::create(item1, item2, item3);
CCMenu*menu = CCMenu::createWithArray(array);
/// Iterate over the menu items
CCObject*obj = NULL;
CCARRAY_FOREACH(array, obj) {
CCMenuItemLabel*item = (CCMenuItemLabel*)obj;
/// Do something with the item...
}要在"run-time“时向菜单中添加项目,请使用CCMenu::addChild方法(并使用removeChild删除项目)。
希望能有所帮助。
https://stackoverflow.com/questions/14907700
复制相似问题