Book Image

Cocos2d-x Cookbook

By : Akihiro Matsuura
Book Image

Cocos2d-x Cookbook

By: Akihiro Matsuura

Overview of this book

Table of Contents (18 chapters)
Cocos2d-x Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating true type font labels


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.

How to do it...

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);

How it works...

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...