Package | starling.text |
Class | public class BitmapFont |
Inheritance | BitmapFont Object |
Implements | ITextCompositor |
<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.
Property | Defined By | ||
---|---|---|---|
baseline : Number The baseline of the font. | BitmapFont | ||
distanceFieldSpread : Number If the font uses a distance field texture, this property returns its spread (i.e. | BitmapFont | ||
lineHeight : Number The height of one line in points. | BitmapFont | ||
name : String 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 | ||
padding : Number The width of a "gutter" around the composed text area, in points. | BitmapFont | ||
size : Number 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 | ||
type : String The type of the bitmap font. | BitmapFont |
Method | Defined By | ||
---|---|---|---|
BitmapFont(texture:Texture = null, fontData:* = null) Creates a bitmap font from the given texture and font data. | BitmapFont | ||
addChar(charID:int, bitmapChar:BitmapChar):void Adds a bitmap char with a certain character ID. | BitmapFont | ||
arrangeChars(width:Number, height:Number, text:String, format:TextFormat, options:TextOptions):Vector.<BitmapCharLocation> Arranges the characters of text inside a rectangle, adhering to the given settings. | 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 | ||
Creates and/or sets up the default MeshStyle to be used for rendering. | BitmapFont | ||
hasChars(text:String):Boolean Checks whether a provided string can be displayed with the font. | BitmapFont |
Method | Defined By | ||
---|---|---|---|
parseFontData(data:*):void Parses the data that's passed as second argument to the constructor. | BitmapFont |
Constant | Defined 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 |
baseline | property |
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.
public function get baseline():Number
public function set baseline(value:Number):void
distanceFieldSpread | property |
distanceFieldSpread:Number
If the font uses a distance field texture, this property returns its spread (i.e. the width of the blurred edge in points).
public function get distanceFieldSpread():Number
public function set distanceFieldSpread(value:Number):void
lineHeight | property |
lineHeight:Number
The height of one line in points.
public function get lineHeight():Number
public function set lineHeight(value:Number):void
name | property |
name:String
The name of the font as it was parsed from the font file.
public function get name():String
public function set name(value:String):void
offsetX | property |
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.
.
public function get offsetX():Number
public function set offsetX(value:Number):void
offsetY | property |
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.
.
public function get offsetY():Number
public function set offsetY(value:Number):void
padding | property |
padding:Number
The width of a "gutter" around the composed text area, in points. This can be used to bring the output more in line with standard TrueType rendering: Flash always draws them with 2 pixels of padding.
The default value is 0.0
.
public function get padding():Number
public function set padding(value:Number):void
size | property |
size:Number
The native size of the font.
public function get size():Number
public function set size(value:Number):void
smoothing | property |
smoothing:String
The smoothing filter that is used for the texture.
public function get smoothing():String
public function set smoothing(value:String):void
texture | property |
texture:Texture
[read-only] The underlying texture that contains all the chars.
public function get texture():Texture
type | property |
type:String
The type of the bitmap font.
The default value is standard
.
public function get type():String
public function set type(value:String):void
See also
BitmapFont | () | Constructor |
public function BitmapFont(texture:Texture = null, fontData:* = null)
Creates a bitmap font from the given texture and font data. If you don't pass any data, the "mini" font will be created.
Parameterstexture:Texture (default = null ) — The texture containing all the glyphs.
| |
fontData:* (default = null ) — Typically an XML file in the standard AngelCode format. Override the
the 'parseFontData' method to add support for additional formats.
|
addChar | () | method |
public function addChar(charID:int, bitmapChar:BitmapChar):void
Adds a bitmap char with a certain character ID.
Parameters
charID:int | |
bitmapChar:BitmapChar |
arrangeChars | () | method |
public function arrangeChars(width:Number, height:Number, text:String, format:TextFormat, options:TextOptions):Vector.<BitmapCharLocation>
Arranges the characters of text inside a rectangle, adhering to the given settings. Returns a Vector of BitmapCharLocations.
BEWARE: This method uses an object pool for the returned vector and all
(returned and temporary) BitmapCharLocation instances. Do not save any references and
always call BitmapCharLocation.rechargePool()
when you are done processing.
Parameters
width:Number | |
height:Number | |
text:String | |
format:TextFormat | |
options:TextOptions |
Vector.<BitmapCharLocation> |
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 )
|
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 |
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 )
|
Vector.<int> |
getDefaultMeshStyle | () | method |
public function getDefaultMeshStyle(previousStyle:MeshStyle, format:TextFormat, options:TextOptions):MeshStyle
Creates and/or sets up the default MeshStyle to be used for rendering.
If previousStyle
has the correct type, it is configured as needed and
then returned; otherwise, a new style is created, configured and returned.
The method may return null
if there are no special style requirements.
Parameters
previousStyle:MeshStyle | |
format:TextFormat | |
options:TextOptions |
MeshStyle |
hasChars | () | method |
public function hasChars(text:String):Boolean
Checks whether a provided string can be displayed with the font.
Parameters
text:String |
Boolean |
parseFontData | () | method |
protected function parseFontData(data:*):void
Parses the data that's passed as second argument to the constructor. Override this method to support different file formats.
Parameters
data:* |
MINI | Constant |
public static const MINI:String = mini
The font name of the embedded minimal bitmap font. Use this e.g. for debug output.
NATIVE_SIZE | Constant |
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.