A bitmap font implementation that handles both regular bitmap fonts and MSDF (Multi-channel Signed Distance Field) fonts. This class manages font textures, character data, kerning, and optional pre-rendering of characters. It supports multiple texture pages and custom shaders, particularly useful for MSDF fonts.

Constructor

new(fontData:BitmapFontData, pages:Map<String, Texture>)

Creates a new BitmapFont instance.

Parameters:

fontData

The font data containing metrics and character information

pages

A map of texture file paths to their corresponding textures

Throws:

String

if fontData or pages are null

Variables

@:value(new IntMap(16, 0.5, true))pages:IntMap<Texture> = new IntMap(16, 0.5, true)

Maps texture page IDs to their corresponding textures. A bitmap font can span multiple texture pages to accommodate large character sets.

read onlymsdf:Bool

Indicates if this font is an MSDF (Multi-channel Signed Distance Field) font. MSDF fonts provide superior scaling quality compared to regular bitmap fonts.

spaceChar:BitmapFontCharacter

Cached reference to the space character (ASCII 32). Used for efficient spacing calculations in text rendering.

@:value(null)pageShaders:Map<Int, Shader> = null

Custom shaders used for rendering characters, stored per texture page. Automatically set up for MSDF fonts using ceramic's MSDF shader.

@:value(null)preRenderedPages:Map<Int, Map<Int, Texture>> = null

Pre-rendered textures for different font sizes, stored per page and size. Used to optimize rendering performance by caching commonly used sizes.

asset:Asset

Reference to the asset that created this font. Used for proper resource management.

Methods

destroy():Void

Cleans up all resources associated with this font including textures, shaders, and pre-rendered pages.

needsToPreRenderAtSize(pixelSize:Int):Bool

Checks if the font needs to be pre-rendered at a specific pixel size.

Parameters:

pixelSize

The target size in pixels

Returns:

True if pre-rendering is needed, false otherwise

preRenderAtSize(pixelSize:Int, done:() ‑> Void):Void

Pre-renders the font at a specific pixel size. Useful for optimizing rendering performance for frequently used sizes.

Parameters:

pixelSize

The target size in pixels

done

Callback function called when pre-rendering is complete

inlinekerning(first:Int, second:Int):Float

Gets the kerning amount between two characters. Kerning improves text appearance by adjusting the space between specific character pairs.

Parameters:

first

The character code of the first glyph

second

The character code of the second glyph

Returns:

The kerning amount (0 if no kerning is defined)

Inherited Events

Defined by Entity

@:dox(show)dispose(entity:Entity):Void

@:dox(show)destroy(entity:Entity):Void

Inherited Variables

Defined by Entity

@:value(null)id:String = null

read onlydestroyed:Bool

read onlydisposed:Bool

@:value(null)read onlyautoruns:Array<Autorun> = null

components:ReadOnlyMap<String, Component>

Public components mapping. Contain components created separately with component() or macro-based components as well.

scriptContent:ScriptContent

Available with script plugin

script:Script

Available with script plugin

Inherited Methods

Defined by Entity

dispose():Void

Schedules destroy, at the end of the current frame.

unbindEvents():Void

Remove all events handlers from this entity.

autorun(run:() ‑> Void, ?afterRun:() ‑> Void):Autorun

Creates a new Autorun instance with the given callback associated with the current entity.

Parameters:

run

The run callback

Returns:

The autorun instance

tween(?easing:Easing, duration:Float, fromValue:Float, toValue:Float, update:(Float, Float) ‑> Void):Tween

Start a tween associated with this entity.

Parameters:

easing

The easing to use

duration

The duration of the tween

fromValue

The start value of the tween

toValue

The end value of the tween

update

An update function called at each iteration of the tween

Returns:

The instance of the created Tween object

eagerTween(?easing:Easing, duration:Float, fromValue:Float, toValue:Float, update:(Float, Float) ‑> Void):Tween

Start an eager tween associated with this entity. This is the same as a regular tween, except that it will start updating itself using current frame's delta time instead of next frame like in a regular tween.

Parameters:

easing

The easing to use

duration

The duration of the tween

fromValue

The start value of the tween

toValue

The end value of the tween

update

An update function called at each iteration of the tween

Returns:

The instance of the created Tween object

@:value({ hasField : false })component<C>(?name:String, ?component:Null<C>, hasField:Bool = false):C