Book Image

Mastering Android Game Development

By : Raul Portales
Book Image

Mastering Android Game Development

By: Raul Portales

Overview of this book

Table of Contents (18 chapters)
Mastering Android Game Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
API Levels for Android Versions
Index

Custom fonts


For app developers, Google has always enforced the use of the system default font, especially since Robotto was introduced. That is the reason why there are no other fonts in the system. However, TextView can use custom fonts in True Type (.ttf) or Open Type (.otf) formats.

When choosing a font, you have lots of choices. There are websites that list lots of fonts that are free to use. Because YASS is meant to be a retro-style shooter, I picked a pixel-art style font called Adore64.

We will store the font files into a folder under assets that we will name ttf, in the same way as we did for sounds.

To load the font in a format that can be used by TextView, we have the Typeface class. The process of loading a font is expensive, so we will do it only once (inside onCreate) and we will keep the Typeface variable as a member of the Activity.

Note

Loading a Typeface is expensive; we should keep it in memory (at the Activity level).

The code we have to add to YassActivity for loading a font...