Provides support for bitmap fonts.
This object supports loading of bitmap fonts with either fixed of variable character spacing and dimensions.
Only Bitmap Font Generator .fnt files are supported. They have to be converted to JSON by the tool bmfont2json. A .fnt file contains references to the image files the font glyphs were rendered to, those image files need to be on the mapping table so they can be loaded.
Note
At the moment only a single image file per font is supported.
Required scripts
The FontManager object requires:
/*{{ javascript("jslib/fontmanager.js") }}*/
Summary
Syntax
var fontManager = FontManager.create(graphicsDevice, requestHandler);
Summary
Creates a Font from a loaded .fnt file and its associated image files.
Syntax
// request font to be loaded
var onload = function onloadFn(font) {};
fontManager.load(path, onload);
// use font when ready
var font = fontManager.get(path);
var textParameters = {
rect: [x, y, width, height],
alignment: windowdef.textalign,
scale: windowdef.textscale,
spacing: windowdef.textspacing
};
font.drawTextRect(text, textParameters);
The font file will be loaded asynchronously. This method returns a Font object, if the font file has already been loaded it returns the requested font, otherwise it returns the default font. The method getNumPendingFonts can be used to check how many of the fonts requested to be loaded are still pending. The callback function is called with the loaded Font as an argument.
Summary
Returns the loaded font stored with the given path or name.
Syntax
var font = fontManager.get(path);
var textParameters = {
rect: [x, y, width, height],
alignment: windowdef.textalign,
scale: windowdef.textscale,
spacing: windowdef.textspacing
};
font.drawTextRect(text, textParameters);
This method returns a Font object, if the font has already been loaded it returns the requested font, otherwise it returns the default font. The method getNumPendingFonts can be used to check how many of the fonts requested to be loaded are still pending.
Summary
Alias one font to another name.
Syntax
fontManager.map(alias, name);
Summary
Get the number of fonts pending load.
Syntax
var numFontsToBeLoaded = fontManager.getNumPendingFonts();
Summary
Check if a font is not pending load.
Syntax
fontManager.isFontLoaded(name);
Returns true if a font has loaded, false otherwise.
Summary
Check if a font is missing.
Syntax
fontManager.isFontMissing(name);
Returns true if the font has not been requested to load, false otherwise.
Summary
Enables remapping of loading paths.
The remapping only affects the loading URLs.
Syntax
fontManager.setPathRemapping(remappingTable, gloablPrefix);
Summary
Calculate text dimensions of a block of text and a font.
Syntax
var textBlockSize = fontManager.calculateTextDimensions(name, text, scale, spacing);
var width = textBlockSize.width;
var height = textBlockSize.height;
var linesWidth = textBlockSize.linesWidth;
var numGlyphs = textBlockSize.numGlyphs;
Returns an object with 3 properties:
Summary
Releases the FontManager object and all the resources it allocated.
Syntax
fontManager.destroy();
Contains information about a bitmap font and provides screen size calculations and geometry generation from given strings.
Summary
Calculate text dimensions of a block of text.
Syntax
var textBlockSize = font.calculateTextDimensions(text, scale, spacing);
var width = textBlockSize.width;
var height = textBlockSize.height;
var numGlyphs = textBlockSize.numGlyphs;
Returns an object with 3 properties:
Summary
Generates vertices for a given text. This method is used internally by drawTextRect to generate the vertices to be drawn.
Syntax
var textParameters = {
rect: [x, y, width, height],
alignment: windowdef.textalign,
scale: windowdef.textscale,
spacing: windowdef.textspacing
};
var vertices = font.generateTextVertices(text, textParameters);
if (vertices)
{
var numVertices = (vertices.length / 4);
vertexBuffer.setData(vertices, 0, numVertices);
}
Text drawing parameters.
Defaults to left-aligned.
Returns an array of numbers, 4 numbers per vertex: X, Y, U, V.
Summary
Draws text.
Syntax
graphicsDevice.setTechnique(textTechnique);
var textParameters = {
rect: [x, y, width, height],
alignment: windowdef.textalign,
scale: windowdef.textscale,
spacing: windowdef.textspacing
};
font.drawTextRect(text, textParameters);
Text drawing parameters.
Defaults to left-aligned.