【Cocos2D-X 游戏引擎】初窥门径(16)几种常用的 CCMenuItem、自定义Button

几种常用的菜单项:


	//字体菜单项
    CCMenuItemFont* itemFont = CCMenuItemFont::create("开始游戏", this, menu_selector(HelloWorld::onMenu));  
      
    //图片菜单项
    CCMenuItemImage* itemImage = CCMenuItemImage::create("CloseNormal.png", "CloseSelected.png", this, menu_selector(HelloWorld::onMenu));  
      
    //文本菜单项  
    CCLabelTTF* label = CCLabelTTF::create("主菜单", "Helvetica", 20);  
    CCMenuItemLabel* itemLabel = CCMenuItemLabel::create(label, this, menu_selector(HelloWorld::onMenu));  
      
    //精灵菜单项
    CCSprite* BtnNormal = CCSprite::create("BtnNormal.png");  
    CCSprite* BtnPressed = CCSprite::create("BtnPressed.png");  
    CCMenuItemSprite* itemSprite = CCMenuItemSprite::create(BtnNormal, BtnPressed, this, menu_selector(HelloWorld::onMenu));  
      
    //开关菜单项  
    CCMenuItemFont* font1 = CCMenuItemFont::create("开");  
    CCMenuItemFont* font2 = CCMenuItemFont::create("关");  
    CCMenuItemToggle* itemToggle = CCMenuItemToggle::createWithTarget(this, menu_selector(HelloWorld::onMenu), font1, font2, NULL);  


利用CCMenuItemSprite自定义Button,有按下效果:

	CCSprite* btnHeroNormal=CCSprite::create("btnHeroNormal.png");
	CCSprite* btnHeroPressed=CCSprite::create("btnHeroPressed.png");
	CCMenuItemSprite* item=CCMenuItemSprite::create(btnHeroNormal, btnHeroPressed, this, menu_selector(HomeLayer::onButton));

	CCMenu* menu=CCMenu::create(item, NULL);
	menu->setPosition(ccp(150, 300));
	this->addChild(menu, 1);

【Cocos2D-X 游戏引擎】初窥门径(16)几种常用的 CCMenuItem、自定义Button_第1张图片





转载请注明出处:http://blog.csdn.net/Vestigge


你可能感兴趣的:(cocos2d-x)