本文整理汇总了C++中LabelBMFont类的典型用法代码示例。如果您正苦于以下问题:C++ LabelBMFont类的具体用法?C++ LabelBMFont怎么用?C++ LabelBMFont使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LabelBMFont类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: showRestartMenu
void HelloWorld::showRestartMenu()
{
Size winSize = Director::getInstance()->getWinSize();
const char *message;
if (_won)
{
message = "You win!";
}
else
{
message = "You lose!";
}
LabelBMFont *label = LabelBMFont::create(message, "Arial.fnt");
label->setScale(0.1f);
label->setPosition(winSize.width / 2, winSize.height * 0.6f);
this->addChild(label);
LabelBMFont *restartLabel = LabelBMFont::create("Restart", "Arial.fnt");
MenuItemLabel *restartItem = MenuItemLabel::create(restartLabel, [](Object *sender){
Director::getInstance()->replaceScene(TransitionZoomFlipX::create(0.5f, HelloWorld::createScene()));
});
restartItem->setScale(0.1f);
restartItem->setPosition(winSize.width / 2, winSize.height * 0.4f);
Menu *menu = Menu::createWithItem(restartItem);
menu->setPosition(Point::ZERO);
this->addChild(menu);
restartItem->runAction(ScaleTo::create(0.5f, 1.0f));
label->runAction(ScaleTo::create(0.5f, 1.0f));
}
示例2: setHighestHistorySorce
void HelloWorld::endScene(EndReason endReason) {
if (_gameOver)
return;
_gameOver = true;
//存储分数
setHighestHistorySorce();
gScore = 0;
auto winSize = Director::getInstance()->getWinSize();
char message[10] = "You Win";
if (endReason == KENDREASONLOSE)
strcpy(message, "You Lose");
LabelBMFont * label;
label = LabelBMFont::create(message,"fonts/Arial.fnt");
label->setScale(0.1);
label->setPosition(Point(winSize.width / 2, winSize.height*0.6));
this->addChild(label);
LabelBMFont * restartLabel;
restartLabel = LabelBMFont::create("Restart", "fonts/Arial.fnt");
auto *restartItem = MenuItemLabel::create(restartLabel,CC_CALLBACK_1(HelloWorld::restartTapped,this));
restartItem->setScale(0.1);
restartItem->setPosition(Point(winSize.width / 2, winSize.height*0.4));
Menu *menu = Menu::create(restartItem, NULL);
menu->setPosition(Point::ZERO);
this->addChild(menu);
// clear label and menu
restartItem->runAction(ScaleTo::create(0.5, 1.0));
label->runAction(ScaleTo::create(0.5, 1.0));
// Terminate update callback
this->unscheduleUpdate();
}
示例3: ScrollingBgLayer
// on "init" you need to initialize your instance
bool OptionsMenu::init()
{
Size visibleSize = CCDirector::sharedDirector()->getVisibleSize();
Vec2 origin = CCDirector::sharedDirector()->getVisibleOrigin();
scrollingBgLayer = new ScrollingBgLayer(3.0);
this->addChild(scrollingBgLayer);
LabelBMFont *nameLabel = LabelBMFont::create("Options Menu","PixelFont.fnt");
nameLabel->setPosition(visibleSize.width/2, visibleSize.height * 0.8);
this->addChild(nameLabel);
MenuItemImage *presetItem = MenuItemImage::create("_bookgame_UI__resume.png",
"_bookgame_UI__resume.png",
CC_CALLBACK_1(OptionsMenu::reset, this));
presetItem->setPosition(ccp(visibleSize.width/2 - visibleSize.width * 0.125, visibleSize.height * 0.5));
MenuItemImage *pmainMenuItem = MenuItemImage::create("_bookgame_UI_mainmenu.png",
"_bookgame_UI_mainmenu.png",
CC_CALLBACK_1(OptionsMenu::mainMenu, this));
pmainMenuItem->setPosition(Vec2(visibleSize.width/2 + visibleSize.width * 0.125, visibleSize.height * 0.5 ));
//sound onoff items
soundOnItem = MenuItemImage::create("_bookgame_UI_soundON.png","_bookgame_UI_soundON.png", this,NULL);
soundOffItem = MenuItemImage::create("_bookgame_UI_soundOFF.png","_bookgame_UI_soundOFF.png", this,NULL);
bool isPaused = CCUserDefault::sharedUserDefault()->getBoolForKey("tinyBazooka_kSoundPausedKey");
MenuItemToggle* soundToggleItem;
if(isPaused == false) {
soundToggleItem = MenuItemToggle::createWithTarget(this,menu_selector(OptionsMenu::SoundOnOff),
soundOnItem, soundOffItem,NULL);
} else {
soundToggleItem = MenuItemToggle::createWithTarget(this,menu_selector(OptionsMenu::SoundOnOff),
soundOffItem, soundOnItem,NULL);
}
soundToggleItem->setPosition(ccp(visibleSize.width* 0.5, visibleSize.height * 0.5 ));
// create menu, it's an autorelease object
Menu* pMenu = Menu::create(pmainMenuItem, presetItem,soundToggleItem, NULL);
pMenu->setPosition(Vec2::ZERO);
this->addChild(pMenu, 10);
this->scheduleUpdate();
return true;
}
示例4: new
//LabelBMFont - Creation & Init
LabelBMFont *LabelBMFont::create(const std::string& str, const std::string& fntFile, float width /* = 0 */, TextHAlignment alignment /* = TextHAlignment::LEFT */,const Vec2& imageOffset /* = Vec2::ZERO */)
{
LabelBMFont *ret = new (std::nothrow) LabelBMFont();
if(ret && ret->initWithString(str, fntFile, width, alignment,imageOffset))
{
ret->autorelease();
return ret;
}
CC_SAFE_DELETE(ret);
return nullptr;
}
示例5: LabelBMFont
NS_CC_BEGIN
LabelBMFont * LabelBMFont::create()
{
LabelBMFont * pRet = new LabelBMFont();
if (pRet && pRet->init())
{
pRet->autorelease();
return pRet;
}
CC_SAFE_DELETE(pRet);
return nullptr;
}
示例6: if
void LayerGameMain::updateBigBoomCount(int bigBoomCount)
{
String strBoomCount;
Sprite * norBoom = Sprite::createWithSpriteFrameName("bomb.png");
Sprite * selBoom = Sprite::createWithSpriteFrameName("bomb.png");
if (bigBoomCount < 0)
{
return;
}
else if (bigBoomCount == 0)
{
if (this->getChildByTag(TAG_BIGBOOM))
{
this->removeChildByTag(TAG_BIGBOOM,true);
}
if (this->getChildByTag(TAG_BIGBOOMCOUNT))
{
this->removeChildByTag(TAG_BIGBOOMCOUNT,true);
}
}
else if (bigBoomCount == 1)
{
if ( !(this->getChildByTag(TAG_BIGBOOM)) )
{
MenuItemSprite * boomItem = MenuItemSprite::create(norBoom,
selBoom,
CC_CALLBACK_1(LayerGameMain::boomMenuCallback,this));
boomItem->setPosition(norBoom->getContentSize().width/2,norBoom->getContentSize().height/2);
Menu * boomMenu = Menu::create(boomItem,nullptr);
boomMenu->setPosition(Point::ZERO);
this->addChild(boomMenu,0,TAG_BIGBOOM);
}
if ( !(this->getChildByTag(TAG_BIGBOOMCOUNT)) )
{
strBoomCount.initWithFormat("X %d",bigBoomCount);
LabelBMFont * labelBoomCount = LabelBMFont::create(strBoomCount.getCString(),"font/font.fnt");
labelBoomCount->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
labelBoomCount->setPosition(Point(norBoom->getContentSize().width,norBoom->getContentSize().height - 30));
this->addChild(labelBoomCount,0,TAG_BIGBOOMCOUNT);
}
}
else if (bigBoomCount > 1 && bigBoomCount < MAX_BIGBOOM_COUNT)
{
strBoomCount.initWithFormat("X %d",bigBoomCount);
LabelBMFont * labelCount = (LabelBMFont *)this->getChildByTag(TAG_BIGBOOMCOUNT);
labelCount->setString(strBoomCount.getCString());
}
}
示例7: boomMenuCallback
void LayerGameMain::boomMenuCallback(cocos2d::Ref * ref)
{
_bigBoomCount--;
String strBoomCount;
strBoomCount.initWithFormat("X %d",_bigBoomCount);
LabelBMFont * labelCount = (LabelBMFont *)this->getChildByTag(TAG_BIGBOOMCOUNT);
labelCount->setString(strBoomCount.getCString());
_score += _enemyLayer->_smallVec.size()*SMALL_SCORE;
_score += _enemyLayer->_midVec.size()*MID_SCORE;
_score += _enemyLayer->_bigVec.size()*BIG_SCORE;
_controlLayer->updateScore(_score);
_enemyLayer->removeAllEnemy();
if (_bigBoomCount == 0)
{
this->removeChildByTag(TAG_BIGBOOM);
this->removeChildByTag(TAG_BIGBOOMCOUNT);
}
}
示例8: ccsf
//ハイスコアラベルの表示
void GameScene::showHighScoreLabel()
{
Size bgSize = m_background->getContentSize();
//ハイスコア表示
int highScore = UserDefault::getInstance()->getIntegerForKey(KEY_HIGHSCORE, 0);
const char* highScoreStr = ccsf("%d", highScore);
LabelBMFont* highScoreLabel = (LabelBMFont*)m_background->getChildByTag(kTagHighScoreLabel);
if(!highScoreLabel)
{
//ハイスコア生成
highScoreLabel = LabelBMFont::create(highScoreStr, FONT_WHITE);
highScoreLabel->setPosition(ccp(bgSize.width * 0.78,bgSize.height * 0.87));
m_background->addChild(highScoreLabel, kZOrderLabel, kTagHighScoreLabel);
}
else
{
highScoreLabel->setString(highScoreStr);
}
}
示例9: BallSprite
BallSprite* BallSprite::createWithNumber(kBallNumber number)
{
BallSprite *ballSprite = new BallSprite();
ballSprite->setNumber(number);
if(ballSprite && ballSprite->initWithFile(PNG_BALL))
{
//ボールの数字をラベルとして付ける
const char* numberString = CCString::createWithFormat("%d", number)->getCString();
LabelBMFont* numberLabel = CCLabelBMFont::create(numberString, FONT_NUMBER);
numberLabel->setPosition(Point(ballSprite->getContentSize().width / 2,ballSprite->getContentSize().height / 2));
numberLabel->setScale(1.8);
ballSprite->addChild(numberLabel, kZOrderNumber, kTagNumber);
//ボールのメモリを自動消去
ballSprite->autorelease();
//作ったSpriteを返す
return ballSprite;
} else {
CC_SAFE_DELETE(ballSprite);
return nullptr;
}
}
示例10: while
//ラベル表示
void GameScene::showLabel()
{
Size bgSize = m_background->getContentSize();
//残数表示
int tagsForLabel[] = {kTagRedLabel, kTagBlueLabel, kTagYellowLabel, kTagGreenLabel, kTagGrayLabel};
const char* fontNames[] = {FONT_RED, FONT_BLUE, FONT_YELLOW, FONT_GREEN, FONT_GRAY};
float heightRate[] = {0.61, 0.51, 0.41, 0.31, 0.21};
//コマの種類のループ
vector<kBlock>::iterator it = blockTypes.begin();
while (it != blockTypes.end()) {
//コマ残数表示
long count = m_blockTags[*it].size();
const char* countStr = ccsf("%02ld", count);
LabelBMFont* label = (LabelBMFont*)m_background->getChildByTag(tagsForLabel[*it]);
if (!label)
{
//コマ残数表示
label = LabelBMFont::create(countStr, fontNames[*it]);
label->setPosition(ccp(bgSize.width * 0.78, bgSize.height * heightRate[*it]));
m_background->addChild(label, kZOrderLabel, tagsForLabel[*it]);
}
else
{
label->setString(countStr);
}
it++;
}
//スコア表示
const char* scoreStr = ccsf("%d", m_score);
LabelBMFont* scoreLabel = (LabelBMFont*)m_background->getChildByTag(kTagScoreLabel);
if (!scoreLabel)
{
//スコア生成
scoreLabel = LabelBMFont::create(scoreStr, FONT_WHITE);
scoreLabel->setPosition(ccp(bgSize.width * 0.78, bgSize.height * 0.75));
m_background->addChild(scoreLabel, kZOrderLabel, kTagScoreLabel);
}
else
{
scoreLabel->setString(scoreStr);
}
}
示例11: addChild
Atlas6::Atlas6()
{
auto s = Director::getInstance()->getWinSize();
LabelBMFont* label = NULL;
label = LabelBMFont::create("FaFeFiFoFu", "fonts/bitmapFontTest5.fnt");
addChild(label);
label->setPosition( Point(s.width/2, s.height/2+50) );
label->setAnchorPoint( Point(0.5f, 0.5f) ) ;
label = LabelBMFont::create("fafefifofu", "fonts/bitmapFontTest5.fnt");
addChild(label);
label->setPosition( Point(s.width/2, s.height/2) );
label->setAnchorPoint( Point(0.5f, 0.5f) );
label = LabelBMFont::create("aeiou", "fonts/bitmapFontTest5.fnt");
addChild(label);
label->setPosition( Point(s.width/2, s.height/2-50) );
label->setAnchorPoint( Point(0.5f, 0.5f) );
}