Cocos2d-x的菜单中提供了多种菜单项的生成方式,他们都继承于MenuItem,如下图
1CCMenuItemLable
包括CCMenuItemAtlasFont和CCMenuItemFont是两种定义菜单项字体的方式,其中CCMenuItemFont是通过设定字体名称来设置字体,这个字体是系统自带的,通过官方TestCpp中的实例可以查看其用法
// Label Item (LabelAtlas)
CCLabelAtlas* labelAtlas = CCLabelAtlas::create("0123456789","fonts/labelatlas.png",16,24,'.');
CCMenuItemLabel* item3 = CCMenuItemLabel::create(labelAtlas,this,menu_selector(MenuLayerMainMenu::menuCallbackDisabled) );
item3->setDisabledColor( ccc3(32,32,64) );
item3->setColor( ccc3(200,200,255) );
// Font Item
CCMenuItemFont *item4 = CCMenuItemFont::create("I toggle enable items",menu_selector(MenuLayerMainMenu::menuCallbackEnable) );
item4->setFontSizeObj(20);
item4->setFontName("Marker Felt");
// Label Item (CCLabelBMFont)
CCLabelBMFont* label = CCLabelBMFont::create("configuration","fonts/bitmapFontTest3.fnt");
CCMenuItemLabel* item5 = CCMenuItemLabel::create(label,menu_selector(MenuLayerMainMenu::menuCallbackConfig));
// Testing issue #500
item5->setScale( 0.8f );
// Events
CCMenuItemFont::setFontName("Marker Felt");
CCMenuItemFont *item6 = CCMenuItemFont::create("Priority Test",menu_selector(MenuLayerMainMenu::menuCallbackPriorityTest));
// Bugs Item
CCMenuItemFont *item7 = CCMenuItemFont::create("Bugs",menu_selector(MenuLayerMainMenu::menuCallbackBugsTest));
// Font Item
CCMenuItemFont* item8 = CCMenuItemFont::create("Quit",menu_selector(MenuLayerMainMenu::onQuit));
CCMenuItemFont* item9 = CCMenuItemFont::create("Remove menu item when moving",
menu_selector(MenuLayerMainMenu::menuMovingCallback));
2.CCMenuItemSprite
// Font Item
CCSprite* spriteNormal = CCSprite::create(s_MenuItem,CCRectMake(0,23*2,115,23));
CCSprite* spriteSelected = CCSprite::create(s_MenuItem,23*1,23));
CCSprite* spriteDisabled = CCSprite::create(s_MenuItem,23*0,23));
CCMenuItemSprite* item1 = CCMenuItemSprite::create(spriteNormal,spriteSelected,spriteDisabled,menu_selector(MenuLayerMainMenu::menuCallback) );
// Image Item
CCMenuItem* item2 = CCMenuItemImage::create(s_Sendscore,s_PressSendscore,menu_selector(MenuLayerMainMenu::menuCallback2) );
2.CCMenuItemToggle
CCMenuItemToggle可以将任意的CCMenuItem封装进去,作为一个按钮式的开关
CCMenuItemToggle* item1 = CCMenuItemToggle::createWithTarget(this,menu_selector(MenuLayer4::menuCallback),CCMenuItemFont::create( "On" ),CCMenuItemFont::create( "Off"),NULL );