1) CCMenuItem*對象在創(chuàng)建出來后并添加到CCMenu*對象后,只要CCMenu對象有釋放,CCMenuItem*對象也將被釋放。即:CCMenuItem*對象不需要再將釋放。。否則可能會蹦。
2) CCMenu*對象被addChild到父對象后,最后只要remove出來就可以。remove出來后,CCMenu*對象就被釋放掉。(原因:因?yàn)镃CMenu*對象被創(chuàng)建出來時(shí),它是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));