In this recipe, we will explain how to create a label with true type fonts. True type fonts are fonts that you can install into your project. Cocos2d-x's project already has two true type fonts, namely arial.ttf
and Maker Felt.ttf
, which are present in the Resources/fonts
folder.
Here's how to create a label by specifying a true type font. The following code can be used for creating a single-line label by using a true type font:
auto label = Label:: createWithTTF("True Type Font", "fonts/Marker Felt.ttf", 40.0f); label->setPosition(size/2); this->addChild(label);
You can create a Label
with a true type font by specifying a label string, the path to the true type font, and the font size. The true type fonts are located in the font
folder of Resources
. Cocos2d-x has two true type fonts, namely arial.ttf
and Marker Felt.ttf
. You can generate Label
objects of different font sizes from one true type font file. If you want to add...