Skip to content

FontAsset Guide

Peter Robinson edited this page May 19, 2018 · 3 revisions

Introduction

All assets are known engine types that allow instances to be created at runtime. The "FontAsset", like all assets, is derived from a base type of "AssetBase". That means it includes all the fields from that type as well as adding its own fields specific to itself.

The FontAsset provides a way to refer to a bitmap font file so that it can be used by the TextSprite object.

TorqueScript Bindings

Exposed Fields

The FontAsset type exposes a single field in addition to those it inherits. Shown are the equivalent methods available that perform the same action in setting and getting the respective field:

  • FontFile
  • setFontFile(string)
  • getFontFile()

Simple, right? Here's an example of a FontAsset:

<FontAsset
 AssetName="ArialFont"
 FontFile="Arial.fnt"
/>

This will produce an asset known as "ArialFont" from the bitmap font file specified, which it expects to be located in the same folder as the XML FontAsset file. As seen in this example, there is no need to make the asset name match the font name, but having matching names can make keeping the revelent files together on disk easier with an alphabetic file sort.

The bitmap font file itself has references to the image or images that contain the actual characters for the font. These images need to be present where the file says they are with an image type that the engine can read (such as .png or .jpg). The FontAsset will read the bitmap font file, find the reference to the images, and automatically load them into the engine. There's no need to create ImageAssets for these files.

You can refer to sub-folders, but do not use the "." to indicate the current folder as this is already implicitly assumed. You can however use ".." to indicate a parent folder but it is highly discouraged to store fonts in parent folders.

You can quickly create bitmap font files using Angle Code's Bitmap Font Generator. There's a config file that will help you get the correct options set located in the ToyAssets module in the font folder. You can also find examples of working bitmap fonts in this folder. When making bitmap fonts, we suggest using white characters on a transparent background. This will allow you to use the blend color to set the color of the font when you use it.