【独立开发人员er Cocos2d-x实战 009】Cocos2dx 菜单项CCMenu使用

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

Scale9Spritehttp://blog.csdn.net/chenqiai0/article/details/46832761


posted @ 2017-06-01 16:09  lytwajue  阅读(180)  评论(0编辑  收藏  举报