BitmapFont
Introduction
BitmapFont is the runtime representation of a .fnt file and its accompanying textures (usually loaded from .png). A BitmapFont includes an array of BitmapCharacterInfo, where each represents one character in the font. A BitmapFont also includes an array of Texture2Ds, each of which represents one page from the exported .pngs.
For information on loading and assigning fonts, see the Fonts page.
Construction Sources
A BitmapFont can be built from several sources:
A
.fntfile path —new BitmapFont("path/to/font.fnt")loads the descriptor from disk and resolves the page textures relative to it.A
Texture2D[]plus an.fnttext string —new BitmapFont(textures, fntText)skips disk I/O entirely. This is the constructor used when generating fonts via KernSmith, where the page textures and.fntmetadata both live in memory.Embedded resources, network responses, or custom pipelines — load the bytes yourself, then feed the resulting textures and
.fnttext into the in-memory constructor above.
A single BitmapFont instance can be assigned to any number of TextRuntimes via TextRuntime.BitmapFont. The atlas textures are shared, so reuse costs nothing extra at draw time.
For the full strategy comparison — when to assign a BitmapFont directly vs. drive fonts through TextRuntime properties — see Font Strategies — Direct BitmapFont Assignment. Baked drop shadow is available on the property path (TextRuntime Fonts); for outline color, gradients, SDF, color fonts, and other KernSmith-only extras, see Advanced Font Effects.
Measuring Text
The BitmapFont class is ultimately responsible for measuring text. Although the TextRuntime instance does provide many functions for measurement and positioning, the BitmapFont class can give more detailed information if necessary.
The following properties provide information about the font:
BaselineY
Returns the number of pixels from the top of a line to the baseline.
Characters
Provides information about each individual character in the font.
DescenderHeight
The number of pixels from the baseline to the bottom of the line.
LineHeightInPixels
Returns the number of pixels from the top of a line to the bottom, including ascenders and descenders.
Last updated
Was this helpful?

