BitmapFont

public class
loom2d.text.BitmapFont

Description

The BitmapFont class parses bitmap font files and arranges the glyphs in the form of a text.

The class parses the XML format as it is used in the AngelCode Bitmap Font Generator or the Glyph Designer. This is what the file format looks like:

<font>
    <info face="BranchingMouse" size="40" />
    <common lineHeight="40" />
    <pages>  <!-- currently, only one page is supported -->
        <page id="0" file="texture.png" />
    </pages>
    <chars>
        <char id="32" x="60" y="29" width="1" height="1" xoffset="0" yoffset="27" xadvance="8" />
        <char id="33" x="155" y="144" width="9" height="21" xoffset="0" yoffset="6" xadvance="9" />
    </chars>
    <kernings> <!-- Kerning is optional -->
        <kerning first="83" second="83" amount="-4"/>
    </kernings>
</font>

Pass an instance of this class to the method registerBitmapFont of the TextField class. Then, set the fontName property of the text field to the name value of the bitmap font. This will make the text field use the bitmap font.

API overview

Constructor

BitmapFont ()

Attributes

Public attributes

baseline: Number read-only

The baseline of the font

lineHeight: Number

The height of one line in pixels

name: String read-only

The name of the font as it was parsed from the font file

size: Number read-only

The native size of the font

Constants

Constants

CHAR_CARRIAGE_RETURN: Number static
CHAR_NEWLINE: Number static
CHAR_SPACE: Number static
CHAR_TAB: Number static
MINI: String static

The font name of the embedded minimal bitmap font

NATIVE_SIZE: Number static

Use this constant for the fontSize property of the TextField class to render the bitmap font in exactly the size it was created

Functions

Public functions

addChar ( charID: Number , bitmapChar: BitmapChar ): Void

Adds a bitmap char with a certain character ID

createSprite ( width: Number , height: Number , text: String , fontSize: Number = , color: Number = 0xff00ff , hAlign: String = center , vAlign: String = center , autoScale: Boolean = true , kerning: Boolean = true , sprite: Sprite = null ): Sprite

Creates a sprite that contains a certain text, made up by one image per char

dispose (): Void

Disposes the texture of the bitmap font!

fillQuadBatch ( quadBatch: QuadBatch , width: Number , height: Number , text: String , fontSize: Number = , color: Number = 0xffffff , hAlign: String = center , vAlign: String = center , autoScale: Boolean = true , kerning: Boolean = true ): Void

Draws text into a QuadBatch

getChar ( charID: Number ): BitmapChar

Returns a single bitmap char with a certain character ID

getStringDimensions ( s: String , maxWidth: Number , maxHeight: Number , size: Number = ): Point
load ( fontSource: String ): BitmapFont static

Constructor

BitmapFont ()

Attributes

baseline: Number

read-only

The baseline of the font.

lineHeight: Number

The height of one line in pixels.

name: String

read-only

The name of the font as it was parsed from the font file.

size: Number

read-only

The native size of the font.

Constants

CHAR_CARRIAGE_RETURN: Number

static

CHAR_NEWLINE: Number

static

CHAR_SPACE: Number

static

CHAR_TAB: Number

static

MINI: String

static

The font name of the embedded minimal bitmap font. Use this e.g. for debug output.

NATIVE_SIZE: Number

static

Use this constant for the fontSize property of the TextField class to render the bitmap font in exactly the size it was created.

Functions

addChar ( charID: Number , bitmapChar: BitmapChar ): Void

Adds a bitmap char with a certain character ID.

Parameters

charID: Number
bitmapChar: BitmapChar


createSprite ( width: Number , height: Number , text: String , fontSize: Number = , color: Number = 0xff00ff , hAlign: String = center , vAlign: String = center , autoScale: Boolean = true , kerning: Boolean = true , sprite: Sprite = null ): Sprite

Creates a sprite that contains a certain text, made up by one image per char.

Parameters

width: Number
height: Number
text: String
fontSize: Number =
color: Number = 0xff00ff
hAlign: String = center
vAlign: String = center
autoScale: Boolean = true
kerning: Boolean = true
sprite: Sprite = null


dispose (): Void

Disposes the texture of the bitmap font!



fillQuadBatch ( quadBatch: QuadBatch , width: Number , height: Number , text: String , fontSize: Number = , color: Number = 0xffffff , hAlign: String = center , vAlign: String = center , autoScale: Boolean = true , kerning: Boolean = true ): Void

Draws text into a QuadBatch.

Parameters

quadBatch: QuadBatch
width: Number
height: Number
text: String
fontSize: Number =
color: Number = 0xffffff
hAlign: String = center
vAlign: String = center
autoScale: Boolean = true
kerning: Boolean = true


getChar ( charID: Number ): BitmapChar

Returns a single bitmap char with a certain character ID.

Parameters

charID: Number


getFullTypeName (): String
Inherited from Object

native

Gets the fully qualified type name of the Object. The fully qualified type name includes the package of the type.


Returns

String fully qualified type name of the Object.

getStringDimensions ( s: String , maxWidth: Number , maxHeight: Number , size: Number = ): Point

Parameters

s: String
maxWidth: Number
maxHeight: Number
size: Number =


getType (): Type
Inherited from Object

native

Gets the Type that describes the Object.


Returns

Type The Type that describes the object.

getTypeName (): String
Inherited from Object

native

Gets the type name of the Object.


Returns

String type name of the Object.

load ( fontSource: String ): BitmapFont

static

Parameters

fontSource: String


toString (): String
Inherited from Object

native

Returns a String that describes the Object. This can be overriden to provide extra details when printing objects using trace().


Returns

String String that described the Object.

: