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


C++ CCMenuItemLabel::initWithTarget方法代码示例

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


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

示例1: init

// on "init" you need to initialize your instance
bool HelloWorld::init() {
	//////////////////////////////
	// 1. super init first
	if (!CCLayer::init()) {
		return false;
	}

	this->setKeypadEnabled(true);
	CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
	CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
	CCSpriteFrameCache* pCache = CCSpriteFrameCache::sharedSpriteFrameCache();
	pCache->addSpriteFramesWithFile("buttons.plist", "buttons.png");

	CCMenu* pMenu = CCMenu::create();

	std::string uname = CCUserDefault::sharedUserDefault()->getStringForKey(
			"UserName");
	CCPoint position = ccp(origin.x + visibleSize.width / 2,
			origin.y + visibleSize.height * 0.9);
	if (uname.empty()) {
		//register or login
	} else {
		CCString *str = CCString::createWithFormat("用户:%s", uname.c_str());
		CCLabelTTF *pName = CCLabelTTF::create(str->getCString(), "Arial.ttf",
				60);
		pName->setPosition(position);
		pName->setColor(ccc3(0, 0, 0));
		this->addChild(pName, 2);
	}

	CCSprite *pBtnSprite = CCSprite::createWithSpriteFrameName(
			"button_large.png");
	CCSize btnSize = pBtnSprite->getContentSize();
	int padding = 15;
	position = position - ccp(0, btnSize.height + padding);
	pBtnSprite->setPosition(position);
	this->addChild(pBtnSprite, 1);

	CCLabelTTF * pLabel = CCLabelTTF::create("普通模式", "Arial.ttf",
			btnSize.height * 0.6);
	pLabel->setColor(ccc3(0, 0, 0));
	CCMenuItemLabel *pPlayItem = CCMenuItemLabel::create(pLabel);
	pPlayItem->setContentSize(btnSize);
	pPlayItem->initWithTarget(this,
			menu_selector(HelloWorld::menuPlayCallback));
	pPlayItem->setPosition(position);
	pMenu->addChild(pPlayItem);

	position = position - ccp(0, btnSize.height + padding);
	pBtnSprite = CCSprite::createWithSpriteFrameName("button_large.png");
	pBtnSprite->setPosition(position);
	this->addChild(pBtnSprite, 1);
	pLabel = CCLabelTTF::create("继续游戏", "Arial.ttf", btnSize.height * 0.6);
	pLabel->setColor(ccc3(0, 0, 0));
	CCMenuItemLabel *pLoadItem = CCMenuItemLabel::create(pLabel);
	pLoadItem->setContentSize(btnSize);
	pLoadItem->initWithTarget(this,
			menu_selector(HelloWorld::menuLoadCallback));
	pLoadItem->setPosition(position);
	pMenu->addChild(pLoadItem);

	position = position - ccp(0, btnSize.height + padding);
	pBtnSprite = CCSprite::createWithSpriteFrameName("button_large.png");
	pBtnSprite->setPosition(position);
	this->addChild(pBtnSprite, 1);
	pLabel = CCLabelTTF::create("回放游戏", "Arial.ttf", btnSize.height * 0.6);
	pLabel->setColor(ccc3(0, 0, 0));
	CCMenuItemLabel *pReplayItem = CCMenuItemLabel::create(pLabel);
	pReplayItem->setContentSize(btnSize);
	pReplayItem->initWithTarget(this,
			menu_selector(HelloWorld::menuReplayCallback));
	pReplayItem->setPosition(position);
	pMenu->addChild(pReplayItem);

	position = position - ccp(0, btnSize.height + padding);
	pBtnSprite = CCSprite::createWithSpriteFrameName("button_large.png");
	pBtnSprite->setPosition(position);
	this->addChild(pBtnSprite, 1);
	pLabel = CCLabelTTF::create("竞赛模式", "Arial.ttf", btnSize.height * 0.6);
	pLabel->setColor(ccc3(0, 0, 0));
	CCMenuItemLabel *pCompetitionItem = CCMenuItemLabel::create(pLabel);
	pCompetitionItem->setContentSize(btnSize);
	pCompetitionItem->initWithTarget(this,
			menu_selector(HelloWorld::menuCompetitionCallback));
	pCompetitionItem->setPosition(position);
	pMenu->addChild(pCompetitionItem);

	position = position - ccp(0, btnSize.height + padding);
	pBtnSprite = CCSprite::createWithSpriteFrameName("button_large.png");
	pBtnSprite->setPosition(position);
	this->addChild(pBtnSprite, 1);
	pLabel = CCLabelTTF::create("编辑模式", "Arial.ttf", btnSize.height * 0.6);
	pLabel->setColor(ccc3(0, 0, 0));
	CCMenuItemLabel *pEditItem = CCMenuItemLabel::create(pLabel);
	pEditItem->setContentSize(btnSize);
	pEditItem->initWithTarget(this,
			menu_selector(HelloWorld::menuEditCallback));
	pEditItem->setPosition(position);
	pMenu->addChild(pEditItem);
//.........这里部分代码省略.........
开发者ID:SpiritRain,项目名称:sudosudoku,代码行数:101,代码来源:HelloWorldScene.cpp


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