Time for action – creating bitmap font labels
Creating a bitmap font is somewhat similar to creating a batch node.
- Continuing with our
createGameScreen
method, add the following lines to thescore
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);
- Add the following line for an icon that appears next to the
_energyDisplay
label:auto icon = Sprite::createWithSpriteFrameName("health_icon.png"); icon->setPosition( Vec2(_screenSize. width * 0.15f, _screenSize...