Cocos2dx中的菜单用CCMenu/Menu类来实现,该类是一个容器,用来装载各种菜单项,用于菜单项可以是图片、系统字体等。
理论就不说了,先上代码:
CCMenuItemToggle* item1 = CCMenuItemToggle::createWithTarget(this, menu_selector(HelloWorld::menuItemToggle), CCMenuItemFont::create("on1"), CCMenuItemFont::create("off1"), CCMenuItemFont::create("on2"), CCMenuItemFont::create("off2"), CCMenuItemFont::create("on3"), CCMenuItemFont::create("off3"), CCMenuItemFont::create("on4"), CCMenuItemFont::create("off4"), NULL); CCMenuItemImage* item2 = CCMenuItemImage::create("CloseNormal.png", "CloseSelected.png", this, menu_selector(HelloWorld::menuItemToggle)); CCLabelTTF *lable = CCLabelTTF::create("CCLabelTTF", "fonts/arial", 32); CCMenuItemLabel *item3 = CCMenuItemLabel::create(lable, this, menu_selector(HelloWorld::menuItemToggle)); CCMenu *menu = CCMenu::create(item1, item2, item3, NULL); menu->alignItemsVerticallyWithPadding(10); addChild(menu); menu->setPosition(visibleSize.width / 2 - 100, visibleSize.height / 2 + 100);同时定义回调函数:
void HelloWorld::menuItemToggle(CCObject *pSender) { CCLOG("HelloWorld::menuItemToggle"); return; }
推荐博客:
【csb】http://blog.csdn.net/chenqiai0/article/details/46633407
【帧动画】http://blog.csdn.net/chenqiai0/article/details/46808109
【制作plist】http://blog.csdn.net/chenqiai0/article/details/46820669
【加载plist】http://blog.csdn.net/chenqiai0/article/details/46820979
【Scale9Sprite】http://blog.csdn.net/chenqiai0/article/details/46832761