当前位置: 首页>>代码示例>>C++>>正文


C++ CCMenuItemFont::setVisible方法代码示例

本文整理汇总了C++中CCMenuItemFont::setVisible方法的典型用法代码示例。如果您正苦于以下问题:C++ CCMenuItemFont::setVisible方法的具体用法?C++ CCMenuItemFont::setVisible怎么用?C++ CCMenuItemFont::setVisible使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CCMenuItemFont的用法示例。


在下文中一共展示了CCMenuItemFont::setVisible方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: init

// 主菜单Layer对象创建时初始化, 用来完成布局主菜单的功能。 包括背景图片、菜单、背景音乐加载等。
bool MainMenu::init()
{
	int remainder;  // 菜单顶部空白
	int divider;    // 菜单间空白
	int halfWidth;

	// 必须先执行基类的方法
	if(!CCLayer::init())
	{
		return false;
	}

	CCSize winSize = CCDirector::sharedDirector()->getWinSize();
	halfWidth = winSize.width / 2;

	// 添加背景图片,放在最底层
	CCSprite* background = CCSprite::create("background.png");
	background->setPosition(ccp(halfWidth, winSize.height / 2));
	addChild(background, 0);

	CCSprite* title = CCSprite::create("title.png");
	title->setAnchorPoint(ccp(0.5, 1));
	title->setScale(0.5);
	title->setPosition(ccp(halfWidth, winSize.height - 20));
	addChild(title, 10);

	// 添加菜单
	CCMenuItemFont* startGame = CCMenuItemFont::create("start", this, menu_selector(MainMenu::startGame));
	CCSize contentSize = startGame->getContentSize();
	divider = contentSize.height;  // 菜单间间隔单项高度的1/3
	remainder = (winSize.height - divider * MAIN_MENU_NUM) * 3 / 5;
	startGame->setAnchorPoint(ccp(0.5, 1));
	startGame->setPosition(ccp(halfWidth, winSize.height - remainder));
	startGame->setEnabled(false);

	CCMenuItemFont* pauseGame = CCMenuItemFont::create("pause", this, menu_selector(MainMenu::pauseGame));
	pauseGame->setAnchorPoint(ccp(0.5, 1));
	pauseGame->setPosition(ccp(halfWidth, winSize.height - remainder - divider));
	pauseGame->setEnabled(false);
	pauseGame->setVisible(true);

	CCMenuItemFont* resumeGame = CCMenuItemFont::create("resume", this, menu_selector(MainMenu::resumeGame));
	resumeGame->setAnchorPoint(ccp(0.5, 1));
	resumeGame->setPosition(ccp(halfWidth, winSize.height - remainder - divider));
	resumeGame->setEnabled(false);
	resumeGame->setVisible(false);

	CCMenuItemFont* setting = CCMenuItemFont::create("setting", this, menu_selector(MainMenu::setting));
	setting->setAnchorPoint(ccp(0.5, 1));
	setting->setPosition(ccp(halfWidth, winSize.height - remainder - 2 * divider));
	setting->setEnabled(false);

	CCMenuItemFont* quit = CCMenuItemFont::create("quit", this, menu_selector(MainMenu::quit));
	quit->setAnchorPoint(ccp(0.5, 1));
	quit->setPosition(ccp(halfWidth, winSize.height - remainder - 3 * divider));
	quit->setEnabled(false);

	CCMenu* mainMenu = CCMenu::create(startGame, pauseGame, resumeGame, setting, quit, NULL);
	mainMenu->setPosition(CCPointZero);
	addChild(mainMenu, 11, MAIN_MENU_TAG);

	// 对背景音乐进行预加载及设置, 默认背景音乐开启
	isSound = true;
	SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic(std::string(CCFileUtils::sharedFileUtils()->fullPathForFilename("background.mp3")).c_str());
	SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(0.5);
	SimpleAudioEngine::sharedEngine()->playBackgroundMusic(std::string(CCFileUtils::sharedFileUtils()->fullPathForFilename("background.mp3")).c_str(), true);

	return true;
}
开发者ID:kyoky82,项目名称:FishingJoy,代码行数:70,代码来源:MainMenu.cpp


注:本文中的CCMenuItemFont::setVisible方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。