menuItem类
MenuItemFont
//文本菜单
MenuItemFont* itemStart=MenuItemFont::create("开始游戏",CC_CALLBACK_1(MenuScenemenuCallBackthis));
itemStart->@H_404_50@setColor(Color3B(0,255));
itemStart->@H_404_50@setPositionY(-200);
itemStart->@H_404_50@setTag(10);
* itemHelp=MenuItemFont游戏帮助));
itemHelp->255));
itemHelp->250);
itemHelp->11);
* itemAbout=MenuItemFont关于));
itemAbout->255));
itemAbout->300);
itemAbout->12);
Menu* menu=Menu::@H_404_50@create(itemStart,itemHelp,itemAbout,NULL);
this->@H_404_50@addChild(menu);
//回调的函数
voidMenuScene::menuCallBack(Ref*obj){}
MenuItemAtlasFont * item=MenuItemAtlasFont::create(“啊!123”,“pic.png”,32,45,’ ’,CC_CALLBACK_1(HelloWorld::MenuCallBack,this));
toggle菜单按钮(切换) 及MenuItemSprite与MenuItemImage的区别
1⃣️
Sprite * goSpriteNormal=Sprite::create(“goPicNormal.png”);
Sprite * goSpriteSelected=Sprite::create(“goPicSelect.png”);
Sprite * stopSpriteNormal=Sprite::create(“stopPicNormal.png”);
Sprite * stopSpriteSelected=Sprite::create(“stopPicSelcet.png”);
auto goMenuItem=MenuItemSprite::create(goSpriteNormal,goSpriteSelected);//由MenuItemSprite创建的按钮 需要sprite 若MenuItemSprite单独使用不作切换,也是可以加回调的
auto stopMenuItem=MenuItemSprite::create(stopSpriteNormal,stopSpriteSelected);
auto toggleMenuItem=MenuItemToggle::createWithCallBack(CC_CALLBACK_1(HelloWorld::onAction,this),goMenuItem,stopMenuItem,NULL);//由以上两个按钮组成切换按钮
toggleMenuItem->setPosition(Vec2(500,500));
auto menu=Menu::create(toggleMenuItem,NULL);
menu->setPosition(Vec2::ZERO);
this->addChild(menu);
2⃣️
auto goMenuItem=MenuItemImage::create(“goPicNormal.png”,“goPicSelect.png”);
auto stopMenuItem=MenuItemImage::create(“stopPicNormal.png”,“stopPicSelcet.png”);//由MenuItemImage创建的按钮仅需要图片即可 若MenuItemImage单独使用不作切换,也是可以在里边加回调的
//由以上两个按钮组成切换按钮
MenuItemImage继承MenuItemSprite 是其子类 MenuItemSprite比较难用 还是用MenuItemImage的好
以下是MenuItemImage继承MenuItemSprite 单独使用时的回调
auto goMenuItem=MenuItemSprite::create(goSpriteNormal,goSpriteSelected,CC_CALLBACK_1(MenuScene::menuCallBackthis));
“goPicNormal.png”“goPicSelect.png”,);
原文链接:https://www.f2er.com/cocos2dx/344239.html