From: http://blog.linguofeng.com/archive/2012/11/14/cocos2d-x-CCMenu.html
一、CCMenuItemSprite 精灵按钮
CCSprite * normal = CCSprite::spriteWithFile("默认状态的图片"); CCSprite * selected = CCSprite::spriteWithFile("选中状态的图片"); CCSprite * disabled = CCSprite::spriteWithFile("禁用状态的图片"); CCMenuItemSprite * item = CCMenuItemSprite::itemFromNormalSprite(normal, selected, disabled, this, menu_selector(Test::callback)); // itemFromNormalSprite(normal, selected, disabled); // itemFromNormalSprite(normal, selected, this, menu_selector(Test::callback)); // itemFromNormalSprite(normal, selected); item->setIsEnabled(false); // 是否可用,默认true
二、CCMenuItemImage 图片按钮
CCMenuItemImage * item = CCMenuItemImage::itemFromNormalImage("默认状态", "选中状态", this, menu_selector(Test::callback)); // itemFromNormalImage("默认状态", "选中状态"); // itemFromNormalImage("默认", "选中", "禁用", this, menu_selector(Test::callback)); // itemFromNormalImage("默认", "选中", "禁用");
三、CCMenuItemLabel label按钮
// 支持CCLabelAtlas、CCLabelBMFont CCLabelAtlas * label = CCLabelAtlas::labelWithString("123", "nums.png", 24, 30, ''); CCMenuItemLabel * item = CCMenuItemLabel::itemWithLabel(label, this, menu_selector(Test::callback)); // itemWithLabel(label); item->setDisabledColor(ccc3(255, 255, 255)); item->setColor(ccc3(0, 0, 0));
四、CCMenuItemFont 字体按钮
CCMenuItemFont * item = CCMenuItemFont::itemFromString("文本", this, menu_selector(Test::callback)); // itemFromString("文本"); item->setFontSizeObj(24); item->setFontName("Monaco"); // 全局字体与大小 CCMenuItemFont::setFontSize("全局字体大小"); CCMenuItemFont::setFontName("全局字体名称");
五、CCMenuItemToggle 开关式按钮
CCMenuItemToggle * item = CCMenuItemToggle::itemWithTarget(this, menu_selector(Test::callback), CCMenuItemFont::itemFromString("On"), CCMenuItemFont::itemFromString("Off"), NULL); item->getSubItems()->addObject(CCMenuItemFont::itemFromString("Other")); item->setSelectedIndex(2);
六、CCMenu
CCMenu * menu = CCMenu::menuWithItems(item1, item2, NULL); menu->alignItemsHorizontally(); // 垂直对齐 menu->alignItemsVertically(); // 水平对象 menu->alignItemsInColumns(2, 1, NULL); // 两行,两列,一列
七、callback
Test::callback(CCObject * sender) { }