Book Image

Libgdx Cross-platform Game Development Cookbook

Book Image

Libgdx Cross-platform Game Development Cookbook

Overview of this book

Table of Contents (20 chapters)
Libgdx Cross-platform Game Development Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Generating and rendering bitmap fonts


While you may be most familiar with TrueType Fonts (TTF), they are not the best supported approach when it comes to font rendering in games; this also applies to the Libgdx environment. Rendering text from a TTF is a costly process because it involves rasterizing the vector representation of the font onto a texture.

Instead, TTF files are baked into textures or bitmap fonts using an offline tool, such as Hiero, as you will see later in this recipe. This way, the graphics system only needs to load a texture and the location of each contained character. Rendering text becomes a lot simpler: rendering multiple regions using additional logic for correct character positioning. Don't worry, Libgdx does all of this for us!

In this recipe, we will create bitmap fonts from TTF files using Hiero, a tool distributed with the Libgdx package. Then, we will use the result to render text in various ways within a Libgdx application.

Note

Libgdx features a FreeType extension...