The menus in COCOS2DX are implemented with the Ccmenu/menu class, which is a container for loading various menu items, such as images, system fonts, and so on.
The theory is not to say, first on the code:
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 (+); AddChild (menu) ; Menu->setposition (VISIBLESIZE.WIDTH/2-VISIBLESIZE.HEIGHT/2 + 100);
Define the callback function at the same time:
void Helloworld::menuitemtoggle (Ccobject *psender) {cclog ("Helloworld::menuitemtoggle"); return;}
The results are as follows:
Recommended Blog:
"CSB" http://blog.csdn.net/chenqiai0/article/details/46633407
"Frame animation" http://blog.csdn.net/chenqiai0/article/details/46808109
"Making plist" http://blog.csdn.net/chenqiai0/article/details/46820669
"Load Plist" http://blog.csdn.net/chenqiai0/article/details/46820979
"scale9sprite" http://blog.csdn.net/chenqiai0/article/details/46832761
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"Independent Developer ER cocos2d-x combat 009" COCOS2DX menu item Ccmenu use