Game Development Reference
In-Depth Information
Time for action - creating bitmap font
labels
Creating a bitmap font is somewhat similar to creating a batch node.
1. Continuing with our createGameScreen method, add the following lines to
the score label:
_scoreDisplay = Label::createWithBMFont("font.fnt",
"0");
_scoreDisplay->setAnchorPoint(Vec2(1,0.5));
_scoreDisplay->setPosition(Vec2 (_screenSize.width *
0.8f, _screenSize.height * 0.94f));
this->addChild(_scoreDisplay);
And then add a label to display the energy level, and set its horizontal alignment to
Right :
_energyDisplay = Label::createWithBMFont("font.fnt",
"100%", TextHAlignment::RIGHT);
_energyDisplay->setPosition(Vec2 (_screenSize.width *
0.3f, _screenSize.height * 0.94f));
this->addChild(_energyDisplay);
2. Add the following line for an icon that appears next to the _energyDisplay la-
bel:
auto icon =
Sprite::createWithSpriteFrameName("health_icon.png");
icon->setPosition( Vec2(_screenSize. width * 0.15f,
_screenSize.height * 0.94f) );
_gameBatchNode->addChild(icon, kBackground);
Search WWH ::




Custom Search