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 bitmap font labels


Lastly, we will explain how to create a label with bitmap type fonts. Bitmap fonts are also fonts that you can install into your project. A bitmap font is essentially an image file that contains a bunch of characters and a control file that details the size and location of each character within the image. If you use bitmap fonts in your game, you can see that the bitmap fonts will be the same size on all devices.

Getting ready

You have to prepare a bitmap font. You can create it by using a tool such as GlyphDesigner. We will explain this tool after Chapter 10, Improving Games with Extra Features. Now, we will use a bitmap font in Cocos2d-x. It is located in the COCOS_ROOT/tests/cpp-tests/Resources/fonts folder. To begin with, you will have to add the files mentioned below to your Resources/fonts folder in your project.

  • future-48.fnt

  • future-48.png

How to do it...

Here's how to create a label by specifying a bitmap font. The following code can be used for creating...