add CCMenu::init() and CCMenu::menu() to create empty menus

This commit is contained in:
Leon 2011-07-28 10:45:32 +08:00
parent c5f7036f7b
commit 4510101e96
2 changed files with 436 additions and 412 deletions

View File

@ -55,6 +55,10 @@ namespace cocos2d{
, m_pSelectedItem(NULL)
{}
virtual ~CCMenu(){}
/** creates an empty CCMenu */
static CCMenu* menu();
/** creates a CCMenu with it's items */
static CCMenu* menuWithItems(CCMenuItem* item, ...);
@ -64,6 +68,8 @@ namespace cocos2d{
*/
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

@ -44,6 +44,18 @@ namespace cocos2d{
//
//CCMenu
//
CCMenu* CCMenu::menu()
{
CCMenu *menu = new CCMenu();
if (menu && menu->init()) {
menu->autorelease();
return menu;
}
CC_SAFE_DELETE(menu)
return 0;
}
CCMenu * CCMenu::menuWithItems(CCMenuItem* item, ...)
{
va_list args;
@ -65,6 +77,12 @@ namespace cocos2d{
return menuWithItems(item, NULL);
}
bool CCMenu::init()
{
va_list args;
return initWithItems(0, args);
}
bool CCMenu::initWithItems(CCMenuItem* item, va_list args)
{
if (CCLayer::init())