前端之家收集整理的这篇文章主要介绍了
Cocos2d-x_CCMenu(菜单类)介绍,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<pre name="code" class="cpp">bool HelloWorld::init()
{
if ( !CCLayer::init() )
{
return false;
}
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
// CCMenuItemFont
CCMenuItemFont *itemFont = CCMenuItemFont::create("开始游戏",this,menu_selector(HelloWorld::menuItemFont));
itemFont->setPosition(ccp(-120,80));
// CCMenuItemImage
CCMenuItemImage *itemImage = CCMenuItemImage::create("CloseNormal.png","CloseSelected.png",menu_selector(HelloWorld::menuItemImage));
itemImage->setPosition(ccp(-20,80));
CCLabelTTF *labelTTF = CCLabelTTF::create("返回游戏","Helvetica",20);
CCMenuItemLabel *itemLabel = CCMenuItemLabel::create(labelTTF,menu_selector(HelloWorld::menuItemLabel));
itemLabel->setPosition(ccp(80,80));
// CCMenuItemSprite
CCSprite *sprite = CCSprite::create("Icon-57.png");
sprite->setColor(ccc3(255,255,0));
CCSprite *sprite2 = CCSprite::create("Icon-57.png");
CCMenuItemSprite *itemSprite = CCMenuItemSprite::create(sprite,sprite2,menu_selector(HelloWorld::menuItemSprite));
itemSprite->setPosition(ccp(-80,-20));
// CCMenuItemToggle
CCMenuItemFont *item1 = CCMenuItemFont::create("音乐开");
CCMenuItemFont *item2 = CCMenuItemFont::create("音乐关");
CCMenuItemToggle *itemToggle = CCMenuItemToggle::createWithTarget(this,menu_selector(HelloWorld::menuItemToggle),item1,item2,NULL);
itemToggle->setPosition(ccp(20,-20));
CCMenu *menu = CCMenu::create(itemFont,itemImage,itemLabel,itemSprite,itemToggle,NULL);
this->addChild(menu);
return true;
}
void HelloWorld::menuItemFont(cocos2d::CCObject *pSender)
{
CCLog("HelloWorld::menuItemFont");
}
void HelloWorld::menuItemImage(cocos2d::CCObject *pSender)
{
CCLog("HelloWorld::menuItemImage");
}
void HelloWorld::menuItemLabel(cocos2d::CCObject *pSender)
{
CCLog("%p",pSender);
}
void HelloWorld::menuItemSprite(cocos2d::CCObject *pSender)
{
CCLog("HelloWorld::menuItemSprite");
}
void HelloWorld::menuItemToggle(cocos2d::CCObject *pSender)
{
CCLog("HelloWorld::menuItemToggle");
}
原文链接:https://www.f2er.com/cocos2dx/346824.html