fixed #986: Add init() member funciton of CCMenu class.

This commit is contained in:
James Chen 2012-02-29 10:07:18 +08:00
parent f166ee2611
commit 6c01009a18
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 * other items. It is used for script, it can't init with undetermined
* number of variables. * 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 */ /** initializes a CCMenu with it's items */
bool initWithItems(CCMenuItem* item, va_list args); bool initWithItems(CCMenuItem* item, va_list args);

View File

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