Merge pull request #736 from dumganhar/iss986_add_init_CCMenu

fixed #986: Add init() member funciton of CCMenu class.
This commit is contained in:
James Chen 2012-02-28 18:14:53 -08:00
commit d753646bcc
2 changed files with 49 additions and 39 deletions

View File

@ -70,7 +70,10 @@ namespace cocos2d{
* other items. It is used for script, it can't init with undetermined
* number of variables.
*/
static CCMenu*menuWithItem(CCMenuItem* item);
static CCMenu* menuWithItem(CCMenuItem* item);
/** initializes an empty CCMenu */
bool init();
/** initializes a CCMenu with it's items */
bool initWithItems(CCMenuItem* item, va_list args);

View File

@ -72,7 +72,7 @@ namespace cocos2d{
return menuWithItems(item, NULL);
}
bool CCMenu::initWithItems(CCMenuItem* item, va_list args)
bool CCMenu::init()
{
if (CCLayer::init())
{
@ -99,7 +99,18 @@ namespace cocos2d{
s.height -= r.size.height;
}
setPosition(ccp(s.width/2, s.height/2));
// [self alignItemsVertically];
m_pSelectedItem = NULL;
m_eState = kCCMenuStateWaiting;
return true;
}
return false;
}
bool CCMenu::initWithItems(CCMenuItem* item, va_list args)
{
if (init())
{
int z=0;
if (item)
@ -113,13 +124,9 @@ namespace cocos2d{
i = va_arg(args, CCMenuItem*);
}
}
// [self alignItemsVertically];
m_pSelectedItem = NULL;
m_eState = kCCMenuStateWaiting;
return true;
}
return false;
}