Packagestarling.text
Classpublic class BitmapFont
InheritanceBitmapFont Inheritance Object
Implements ITextCompositor

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.



Public Properties
 PropertyDefined By
  baseline : Number
The baseline of the font.
BitmapFont
  lineHeight : Number
The height of one line in points.
BitmapFont
  name : String
[read-only] The name of the font as it was parsed from the font file.
BitmapFont
  offsetX : Number
An offset that moves any generated text along the x-axis (in points).
BitmapFont
  offsetY : Number
An offset that moves any generated text along the y-axis (in points).
BitmapFont
  size : Number
[read-only] The native size of the font.
BitmapFont
  smoothing : String
The smoothing filter that is used for the texture.
BitmapFont
  texture : Texture
[read-only] The underlying texture that contains all the chars.
BitmapFont
Public Methods
 MethodDefined By
  
BitmapFont(texture:Texture = null, fontXml:XML = null)
Creates a bitmap font by parsing an XML file and uses the specified texture.
BitmapFont
  
addChar(charID:int, bitmapChar:BitmapChar):void
Adds a bitmap char with a certain character ID.
BitmapFont
  
clearMeshBatch(meshBatch:MeshBatch):void
Clears the MeshBatch (filled by the same class) and disposes any resources that are no longer needed.
BitmapFont
  
createSprite(width:Number, height:Number, text:String, format:TextFormat, options:TextOptions = null):Sprite
Creates a sprite that contains a certain text, made up by one image per char.
BitmapFont
  
dispose():void
Disposes the texture of the bitmap font!
BitmapFont
  
fillMeshBatch(meshBatch:MeshBatch, width:Number, height:Number, text:String, format:TextFormat, options:TextOptions = null):void
Draws text into a QuadBatch.
BitmapFont
  
getChar(charID:int):BitmapChar
Returns a single bitmap char with a certain character ID.
BitmapFont
  
getCharIDs(out:Vector.<int> = null):Vector.<int>
Returns a vector containing all the character IDs that are contained in this font.
BitmapFont
  
hasChars(text:String):Boolean
Checks whether a provided string can be displayed with the font.
BitmapFont
Public Constants
 ConstantDefined By
  MINI : String = mini
[static] The font name of the embedded minimal bitmap font.
BitmapFont
  NATIVE_SIZE : int = -1
[static] Use this constant for the fontSize property of the TextField class to render the bitmap font in exactly the size it was created.
BitmapFont
Property Detail
baselineproperty
baseline:Number

The baseline of the font. This property does not affect text rendering; it's just an information that may be useful for exact text placement.


Implementation
    public function get baseline():Number
    public function set baseline(value:Number):void
lineHeightproperty 
lineHeight:Number

The height of one line in points.


Implementation
    public function get lineHeight():Number
    public function set lineHeight(value:Number):void
nameproperty 
name:String  [read-only]

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


Implementation
    public function get name():String
offsetXproperty 
offsetX:Number

An offset that moves any generated text along the x-axis (in points). Useful to make up for incorrect font data.

The default value is 0..


Implementation
    public function get offsetX():Number
    public function set offsetX(value:Number):void
offsetYproperty 
offsetY:Number

An offset that moves any generated text along the y-axis (in points). Useful to make up for incorrect font data.

The default value is 0..


Implementation
    public function get offsetY():Number
    public function set offsetY(value:Number):void
sizeproperty 
size:Number  [read-only]

The native size of the font.


Implementation
    public function get size():Number
smoothingproperty 
smoothing:String

The smoothing filter that is used for the texture.


Implementation
    public function get smoothing():String
    public function set smoothing(value:String):void
textureproperty 
texture:Texture  [read-only]

The underlying texture that contains all the chars.


Implementation
    public function get texture():Texture
Constructor Detail
BitmapFont()Constructor
public function BitmapFont(texture:Texture = null, fontXml:XML = null)

Creates a bitmap font by parsing an XML file and uses the specified texture. If you don't pass any data, the "mini" font will be created.

Parameters
texture:Texture (default = null)
 
fontXml:XML (default = null)
Method Detail
addChar()method
public function addChar(charID:int, bitmapChar:BitmapChar):void

Adds a bitmap char with a certain character ID.

Parameters

charID:int
 
bitmapChar:BitmapChar

clearMeshBatch()method 
public function clearMeshBatch(meshBatch:MeshBatch):void

Clears the MeshBatch (filled by the same class) and disposes any resources that are no longer needed.

Parameters

meshBatch:MeshBatch

createSprite()method 
public function createSprite(width:Number, height:Number, text:String, format:TextFormat, options:TextOptions = null):Sprite

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

Parameters

width:Number
 
height:Number
 
text:String
 
format:TextFormat
 
options:TextOptions (default = null)

Returns
Sprite
dispose()method 
public function dispose():void

Disposes the texture of the bitmap font!

fillMeshBatch()method 
public function fillMeshBatch(meshBatch:MeshBatch, width:Number, height:Number, text:String, format:TextFormat, options:TextOptions = null):void

Draws text into a QuadBatch.

Parameters

meshBatch:MeshBatch
 
width:Number
 
height:Number
 
text:String
 
format:TextFormat
 
options:TextOptions (default = null)

getChar()method 
public function getChar(charID:int):BitmapChar

Returns a single bitmap char with a certain character ID.

Parameters

charID:int

Returns
BitmapChar
getCharIDs()method 
public function getCharIDs(out:Vector.<int> = null):Vector.<int>

Returns a vector containing all the character IDs that are contained in this font.

Parameters

out:Vector.<int> (default = null)

Returns
Vector.<int>
hasChars()method 
public function hasChars(text:String):Boolean

Checks whether a provided string can be displayed with the font.

Parameters

text:String

Returns
Boolean
Constant Detail
MINIConstant
public static const MINI:String = mini

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

NATIVE_SIZEConstant 
public static const NATIVE_SIZE:int = -1

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