diff --git a/cocos2dx/menu_nodes/CCMenuItem.cpp b/cocos2dx/menu_nodes/CCMenuItem.cpp index 3a82509ce3..64a5040d4c 100644 --- a/cocos2dx/menu_nodes/CCMenuItem.cpp +++ b/cocos2dx/menu_nodes/CCMenuItem.cpp @@ -714,6 +714,24 @@ CCArray* CCMenuItemToggle::getSubItems() return m_pSubItems; } +CCMenuItemToggle * CCMenuItemToggle::createWithTarget(CCObject* target, SEL_MenuHandler selector, CCArray* menuItems) +{ + CCMenuItemToggle *pRet = new CCMenuItemToggle(); + pRet->CCMenuItem::initWithTarget(target, selector); + pRet->m_pSubItems = CCArray::create(); + pRet->m_pSubItems->retain(); + + for (int z=0; z < menuItems->count(); z++) + { + CCMenuItem* menuItem = (CCMenuItem*)menuItems->objectAtIndex(z); + pRet->m_pSubItems->addObject(menuItem); + } + + pRet->m_uSelectedIndex = UINT_MAX; + pRet->setSelectedIndex(0); + return pRet; +} + CCMenuItemToggle * CCMenuItemToggle::createWithTarget(CCObject* target, SEL_MenuHandler selector, CCMenuItem* item, ...) { va_list args; diff --git a/cocos2dx/menu_nodes/CCMenuItem.h b/cocos2dx/menu_nodes/CCMenuItem.h index 04290de5e5..660099e565 100644 --- a/cocos2dx/menu_nodes/CCMenuItem.h +++ b/cocos2dx/menu_nodes/CCMenuItem.h @@ -322,6 +322,9 @@ public: , m_pSubItems(NULL) {} virtual ~CCMenuItemToggle(); + + ** creates a menu item from a CCArray with a target selector */ + static CCMenuItemToggle * createWithTarget(CCObject* target, SEL_MenuHandler selector, CCArray* menuItems); /** creates a menu item from a list of items with a target/selector */ static CCMenuItemToggle* createWithTarget(CCObject* target, SEL_MenuHandler selector, CCMenuItem* item, ...);