FontAsset

EntityAssetceramic.FontAsset (Class)

Asset type for loading bitmap fonts.

Supports loading:

  • AngelCode BMFont format (.fnt files)
  • TrueType/OpenType fonts (.ttf/.otf) that have been pre-converted to bitmap fonts

A bitmap font consists of:

  • Font data file (.fnt) describing character metrics
  • One or more texture pages containing the rendered glyphs

Features:

  • Multi-page font support
  • Automatic density selection for font textures
  • Hot reload support
  • Automatic Text visual updates when font is replaced
var assets = new Assets();
assets.addFont('arial.fnt');
assets.addFont('roboto.ttf'); // Assumes roboto.fnt exists
assets.load();

// Use loaded font
var text = new Text();
text.font = assets.font('arial');

Instance Members

fontData: BitmapFontData

The parsed font data containing character metrics and layout information. Available after successful loading.


pages: Map

Map of texture page paths to loaded textures. Bitmap fonts can use multiple texture pages for large character sets.


The loaded BitmapFont instance. Observable property that updates when the font is loaded or replaced. Null until the asset is successfully loaded.


invalidateFont(): Void

load(): Void

Load the font data and associated texture pages. For TTF/OTF fonts, looks for pre-converted .fnt files. Handles multi-page fonts by loading all required textures. Emits complete event when finished.


destroy(): Void

new(name: String, ?variant: String, ?options: Null<AssetOptions>): Void

Create a new font asset.

Name Type Default Description
name String Font file name (.fnt, .ttf, or .otf)
variant String (optional) Optional variant suffix
options Null<AssetOptions> (optional) Loading options (font-specific options depend on backend)

Private Members

unobservedFont: BitmapFont

transformedPath: String

emitReplaceFont(newFont: BitmapFont, prevFont: BitmapFont): Void

Emitted when the font is replaced (e.g., during hot reload). All Text visuals using the previous font are automatically updated.

Name Type Description
newFont BitmapFont The newly loaded font
prevFont BitmapFont The previous font being replaced

emitFontChange(current: BitmapFont, previous: BitmapFont): Void

Event when font field changes.

Name Type
current BitmapFont
previous BitmapFont

texturesDensityDidChange(newDensity: Float, prevDensity: Float): Void

Handle screen density changes by reloading the font at appropriate resolution. This ensures text remains crisp when display density changes.

Name Type
newDensity Float
prevDensity Float

checkTexturesDensity(): Void

assetFilesDidChange(newFiles: ReadOnlyMap<String, Float>, previousFiles: ReadOnlyMap<String, Float>): Void

Handle file system changes for hot reload. Monitors both the font data file and texture pages for changes.

Name Type
newFiles ReadOnlyMap<String, Float>
previousFiles ReadOnlyMap<String, Float>

Metadata

Name Parameters
:build tracker.macros.EventsMacro.build()
:autoBuild tracker.macros.EventsMacro.build()
:build ceramic.macros.EntityMacro.buildForCompletion()
:autoBuild ceramic.macros.EntityMacro.buildForCompletion()
:build tracker.macros.ObservableMacro.build()
:autoBuild tracker.macros.ObservableMacro.build()