本文整理汇总了C++中CCMenuItemLabel::setContentSize方法的典型用法代码示例。如果您正苦于以下问题:C++ CCMenuItemLabel::setContentSize方法的具体用法?C++ CCMenuItemLabel::setContentSize怎么用?C++ CCMenuItemLabel::setContentSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCMenuItemLabel
的用法示例。
在下文中一共展示了CCMenuItemLabel::setContentSize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
//.........这里部分代码省略.........
示例2: addStatsLayer
void PauseLayer::addStatsLayer() {
statsLayer = CCLayer::create();
statsLayer->setPosition(ccp(winSize.width * 0, winSize.height * 0));
float scale = Utility::isIPad() ? 1 : 0.7;
CCLabelBMFont *labelObj = CCLabelBMFont::create("stats", kFontChubby, 0);
labelObj->setPosition(ccp(winSize.width * 0.5, winSize.height * 0.93));
labelObj->setScale(scale);
statsLayer->addChild(labelObj, 2);
CCLabelBMFont *thisGameLabel = CCLabelBMFont::create("this game", kFontChubby, 0);
thisGameLabel->setScale(scale);
thisGameItem = CCMenuItemLabel::create(thisGameLabel, this, menu_selector(PauseLayer::menuCallBack) );
thisGameItem->setContentSize(CCSize(thisGameItem->getContentSize() * scale));
thisGameItem->setTag(7);
CCLabelBMFont *slashLabel = CCLabelBMFont::create("/", kFontChubby, 0);
slashLabel->setScale(scale);
CCMenuItemLabel *slashItem = CCMenuItemLabel::create(slashLabel, this, menu_selector(PauseLayer::menuCallBack) );
slashItem->setContentSize(CCSize(slashItem->getContentSize() * scale));
CCLabelBMFont *recordsLabel = CCLabelBMFont::create("records", kFontChubby, 0);
recordsLabel->setScale(scale);
recordsItem = CCMenuItemLabel::create(recordsLabel, this, menu_selector(PauseLayer::menuCallBack) );
recordsItem->setContentSize(CCSize(recordsItem->getContentSize() * scale));
recordsItem->setTag(8);
CCMenu *thisGameRecordsMenu = CCMenu::create(thisGameItem, slashItem, recordsItem, NULL);
thisGameRecordsMenu->alignItemsHorizontallyWithPadding(winSize.width * 0.01);
thisGameRecordsMenu->setPosition(ccp(winSize.width * 0.5, winSize.height * 0.8));
statsLayer->addChild(thisGameRecordsMenu, 2);
createButton("btnObj.png", 6, ccp(winSize.width * 0.30, winSize.height * 0.93));
const char *score = NULL;
const char *distance = NULL;
const char *wallsSmashed = NULL;
const char *tightSqueezes = NULL;
const char *longestGamePlayed = NULL;
if (isCallFromRecords) {
CCSprite *coinSprite = CCSprite::createWithSpriteFrameName("coin_0.png");
coinSprite->setPosition(ccp(winSize.width * 0.75, winSize.height * 0.65));
statsLayer->addChild(coinSprite, 2);
const char *totalCoins = CCString::createWithFormat("%d", gLayer->coinScore)->getCString();
createLabelForStats("", totalCoins, ccp(coinSprite->getPositionX() + winSize.width * 0.05, coinSprite->getPositionY()), statsLayer);
score = CCString::createWithFormat("%d", gLayer->score)->getCString();
distance = CCString::createWithFormat("%d meters", gLayer->distance)->getCString();
wallsSmashed = CCString::createWithFormat("%d", gLayer->wallSmashed)->getCString();
tightSqueezes = CCString::createWithFormat("%d", Utility::getTotalTightSqueezes())->getCString();
longestGamePlayed = CCString::createWithFormat("%02dm%02ds", gLayer->minute, gLayer->seconds)->getCString();
} else {
const char *playerName = CCString::createWithFormat("(%s)", Utility::getPlayerName(0)->getCString())->getCString();
createLabelForStats("", playerName, ccp(winSize.width * 0.65, winSize.height * 0.65), statsLayer);
int longestGame = Utility::getLongestGame();
int min = longestGame / 60;
int sec = longestGame % 60;
longestGamePlayed = CCString::createWithFormat("%02dm%02ds", min, sec)->getCString();
score = CCString::createWithFormat("%d", Utility::getPlayerScore(0))->getCString();
distance = CCString::createWithFormat("%d meters", Utility::getLongestDistance())->getCString();
wallsSmashed = CCString::createWithFormat("%d", Utility::getTotalWallSmashedLifeTime())->getCString();
tightSqueezes = CCString::createWithFormat("%d", Utility::getTotalTightSqueezesLifeTime())->getCString();
}
createLabelForStats("score:", score, ccp(winSize.width * 0.55, winSize.height * 0.65), statsLayer);
createLabelForStats("distance:", distance, ccp(winSize.width * 0.55, winSize.height * 0.55), statsLayer);
createLabelForStats("walls smashed:", wallsSmashed, ccp(winSize.width * 0.55, winSize.height * 0.45), statsLayer);
createLabelForStats("tight squeezes:", tightSqueezes, ccp(winSize.width * 0.55, winSize.height * 0.35), statsLayer);
createLabelForStats("game time:", longestGamePlayed, ccp(winSize.width * 0.55, winSize.height * 0.25), statsLayer);
addChild(statsLayer, 1);
}