[2.x] Cocos2d-x之CCMenu

前端之家收集整理的这篇文章主要介绍了[2.x] Cocos2d-x之CCMenu前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

From: http://blog.linguofeng.com/archive/2012/11/14/cocos2d-x-CCMenu.html

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,this,menu_selector(Test::callback));
                                         // itemFromNormalSprite(normal,selected);
item->setIsEnabled(false);     // 是否可用,默认true
CCMenuItemImage * item = CCMenuItemImage::itemFromNormalImage("默认状态", "选中状态", menu_selector(Test::callback));
                                       // itemFromNormalImage("默认状态","选中状态");
                                       // itemFromNormalImage("默认","选中","禁用",menu_selector(Test::callback));
                                       // itemFromNormalImage("默认","禁用");
// 支持CCLabelAtlas、CCLabelBMFont
CCLabelAtlas * label = CCLabelAtlas::labelWithString("123", "nums.png", 24, 30, '');
CCMenuItemLabel * item = CCMenuItemLabel::itemWithLabel(label, menu_selector(Test::callback));
                                       // itemWithLabel(label);
item->setDisabledColor(ccc3(255, 255, 255));
item->setColor(ccc3(0, 0, 0));
CCMenuItemFont * item = CCMenuItemFont::itemFromString("文本", menu_selector(Test::callback));
                                     // itemFromString("文本");
item->setFontSizeObj(24);
item->setFontName("Monaco");

// 全局字体与大小
CCMenuItemFont::setFontSize("全局字体大小");
CCMenuItemFont::setFontName("全局字体名称");
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 * menu = CCMenu::menuWithItems(item1, item2, NULL);
menu->alignItemsHorizontally();         // 垂直对齐
menu->alignItemsVertically();           // 水平对象
menu->alignItemsInColumns(2, 1, NULL);  // 两行,两列,一列
Test::callback(CCObject * sender)
{

}
原文链接:https://www.f2er.com/cocos2dx/344999.html

猜你在找的Cocos2d-x相关文章