下面将学习几种常见的菜单的创建方式,菜单选择也是游戏中必备的功能之一。
//菜单创建 CCLabelTTF *label = CCLabelTTF::create(G2U("菜单选项"),"微软雅黑",25); label->setPosition(ccp(100,250)); //this->addChild(sp,1); CCMenuItemLabel * item1 = CCMenuItemLabel::create(label,this,menu_selector(HelloWorld::MenuCallBack)); //item1->setPosition(ccp(100,100)); CCMenuItemFont *item2 = CCMenuItemFont::create("item2",this,menu_selector(HelloWorld::MenuCallBack)); item2->setPosition(ccp(100,200)); //this->addChild(item2); CCSprite * sp1 = CCSprite::create("CloseNormal.png"); CCSprite * sp2 = CCSprite::create("CloseSelected.png"); CCMenuItemSprite * item3 = CCMenuItemSprite::create(sp1,sp2,this,menu_selector(HelloWorld::MenuCallBack)); item3->setPosition(ccp(100,70)); //this->addChild(item3); CCMenuItemImage * item4 = CCMenuItemImage::create("CloseNormal.png","CloseSelected.png",this,menu_selector(HelloWorld::MenuCallBack)); item4->setPosition(ccp(100,140)); //this->addChild(item4); CCMenuItemToggle * toggle = CCMenuItemToggle::createWithTarget(this,menu_selector(HelloWorld::MenuCallBack),CCMenuItemFont::create("On"),CCMenuItemFont::create("Off"),NULL); toggle->setPosition(100,30); //this->addChild(toggle); CCMenu * menu = CCMenu::create(item1,item2,item3,item4,toggle,NULL); menu->setPosition(ccp(100,0)); addChild(menu);回调函数
void HelloWorld::MenuCallBack(CCObject *pSender) { }
附带一下Cocos2dx开发几种常用的开发工具
欢迎关注我的围脖
==================== 迂者 丁小未 CSDN博客专栏=================
MyBlog:http://blog.csdn.net/dingxiaowei2013 MyQQ:1213250243
Unity QQ群:375151422 cocos2dx QQ群:280818155
====================== 相互学习,共同进步 ===================