2013-02-16 3 views
0

, пожалуйста, помогите мне, я новичок в cocos2d-x. У меня есть список предметов. Как я могу сделать это с помощью массива элементов, используя CCMenu :: createWithArray, чтобы показать этот список в конце? Я хочу управлять массивом меню, добавлять/удалять элементы из массива (из моего меню списка).Получите массив элементов. Используйте 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); 

      ... 

``

ответ

0

Я не уверен, чтобы понять ваш вопрос ... но вот как вы можете создайте CCMenu, используя CCArray.

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... 
} 

Чтобы добавить пункт в меню на «время выполнения», а затем использовать метод CCMenu :: AddChild (и RemoveChild для удаления элемента).

Надеюсь, это поможет.

+0

большое спасибо! – user2077802

+0

Добро пожаловать. Пожалуйста, проголосуйте, если вы найдете полезную информацию anwser;) –

Смежные вопросы