1) CCMenuItem*对象在创建出来后并添加到CCMenu*对象后,只要CCMenu对象有释放,CCMenuItem*对象也将被释放。即:CCMenuItem*对象不需要再将释放。。否则可能会蹦。
2) CCMenu*对象被addChild到父对象后,最后只要remove出来就可以。remove出来后,CCMenu*对象就被释放掉。(原因:因为CCMenu*对象被创建出来时,它是autorelease()的)
ccColor3B color;
color.r = 0;
color.g = 0;
color.b = 255;
m_pPlayMenuItem = CCMenuItemFont::itemFromString("Play", this, menu_selector(CWelcomeScene::OnPlayGameMenuItemClicked));
((CCMenuItemFont*)m_pPlayMenuItem)->setFontSizeObj(12);
((CCMenuItemFont*)m_pPlayMenuItem)->setColor(color);
color.r = 255;
color.g = 0;
color.b = 0;
m_pExitMenuItem = CCMenuItemFont::itemFromString("Exit", this, menu_selector(CWelcomeScene::OnExitMenuItemClicked));
((CCMenuItemFont*)m_pExitMenuItem)->setFontSizeObj(12);
((CCMenuItemFont*)m_pExitMenuItem)->setColor(color);
if (NULL == m_pMenu)
{
m_pMenu = CCMenu::menuWithItems(m_pPlayMenuItem, m_pExitMenuItem, NULL);
this->addChild(m_pMenu, 1);
m_pMenu->alignItemsVerticallyWithPadding(0.0f);
}
m_pPlayMenuItem = CCMenuItemImage::itemFromNormalImage(g_pcszStartNormalMI, g_pcszStartSelectedMI, this, menu_selector(CWelcomeScene::OnPlayGameMenuItemClicked));
m_pExitMenuItem = CCMenuItemImage::itemFromNormalImage(g_pcszCloseNormalMI, g_pcszCloseSelectedMI, this, menu_selector(CWelcomeScene::OnExitMenuItemClicked));
m_pPlayMenuItem->setScale(0.4f);
m_pMenu = CCMenu::menuWithItems(m_pPlayMenuItem, m_pExitMenuItem, NULL);
this->addChild(m_pMenu, 1);
float fX = GetCurrentWinSize(true).width / 2.0f - 10.0f;
float fY = -(GetCurrentWinSize(false).height / 2.0f) + 5.0f;
m_pExitMenuItem->setAnchorPoint(ccp(1.0, 0.0f));
m_pExitMenuItem->setPosition(ccp(fX, fY));
fX -= m_pExitMenuItem->getContentSize().width + 2.0f;
fY -= 2.0f;
m_pPlayMenuItem->setAnchorPoint(ccp(1.0f, 0.0f));
m_pPlayMenuItem->setPosition(ccp(fX, fY));