/1.CCMenuItemFont 字体菜单 CCMenuItemFont *pMenuFont=CCMenuItemFont::create("Method", this, menu_selector(HelloWorld::menuFontMethod)); pMenuFont->setPosition(ccp(100,100)); //2.CCMenuItemImage 图片菜单项 // add a "close" icon to exit the progress. it's an autorelease object /** @brief CCMenuItemImage accepts images as items. The images has 3 different states: - unselected image - selected image - disabled image For best results try that all images are of the same size */ /** creates a menu item with a normal and selected image with target/selector */ CCMenuItemImage *pCloseItem = CCMenuItemImage::create( "CloseNormal.png", "CloseSelected.png", this, menu_selector(HelloWorld::menuCloseCallback) ); pCloseItem->setPosition( ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20) ); //3.CCMenuItemLabel 文本菜单项 CCLabelTTF *label=CCLabelTTF::create("返回主菜单", "Helvetica", 20); CCMenuItemLabel *pMenuLabel=CCMenuItemLabel::create(label, this, menu_selector(HelloWorld::menuBackMainMethod)); pMenuFont->setPosition(ccp(80, 80)); // create menu, it's an autorelease object CCMenu* pMenu = CCMenu::create(pCloseItem,pMenuFont,pMenuLabel, NULL); pMenu->setPosition( CCPointZero ); this->addChild(pMenu, 1);
//4.CCMenuItemSprite 精灵菜单项 CCSprite *pSrite=CCSprite::create("Icon-72.png"); CCSprite *pSprite2=CCSprite::create("Icon-72.png"); pSprite2->setColor(ccc3(0, 255, 0)); CCMenuItemSprite *menuSprite=CCMenuItemSprite::create(pSrite,pSprite2,this, menu_selector(HelloWorld::menuSpriteMethod)); menuSprite->setPosition(ccp(200,200)); // create menu, it's an autorelease object CCMenu* pMenu = CCMenu::create( menuSprite,NULL); pMenu->setPosition( CCPointZero ); this->addChild(pMenu, 1); void HelloWorld::menuSpriteMethod(CCObject* pSender) { cout<<"this is spriteMenu"<<endl; }
//5.CCMenuItemToggle 开发菜单项 CCMenuItemFont *fontMenu1=CCMenuItemFont::create("音乐开"); CCMenuItemFont *fontMenu2=CCMenuItemFont::create("音乐关"); CCMenuItemToggle *toggleItem=CCMenuItemToggle::createWithTarget(this, menu_selector(HelloWorld::menuToggleMethod), fontMenu1,fontMenu2,NULL); toggleItem->setPosition(ccp(200, 200)); // create menu, it's an autorelease object CCMenu* pMenu = CCMenu::create( toggleItem,NULL); pMenu->setPosition( CCPointZero ); this->addChild(pMenu, 1); void HelloWorld::menuToggleMethod(CCObject* pSender) { cout<<"this is 开关菜单项"<<endl; }