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, globalPrefix);
Summary
Calculate text dimensions of a block of text and a font.
Syntax
var dimensions = fontManager.calculateTextDimensions(name, text, scale, spacing);
var width = dimensions.width;
var height = dimensions.height;
var linesWidth = dimensions.linesWidth;
var numGlyphs = dimensions.numGlyphs;
var glyphCounts = dimensions.glyphCounts;
Returns an object with 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 dimensions = font.calculateTextDimensions(text, scale, spacing,
lineSpacing, dimensions);
var width = dimensions.width;
var height = dimensions.height;
var linesWidth = dimensions.linesWidth;
var numGlyphs = dimensions.numGlyphs;
var glyphCounts = dimensions.glyphCounts;
Returns an object with properties:
Modified SDK 0.28.0
Replaces function previously called generateTextVertices
Summary
For a given bit of text, generates the vertices corresponding to a specific texture page. This method is used internally by drawTextRect to generate the vertices to be drawn for a given texture page. It is not recommended for external use and requires knowledge of the FontManager implementation details.
Syntax
var textParameters = {
rect: [x, y, width, height],
alignment: windowdef.textalign,
scale: windowdef.textscale,
spacing: windowdef.textspacing
};
if (dimensions)
{
textParameters.dimensions = dimensions;
}
var drawCtx = font.generatePageTextVertices(text, textParameters, 0);
if (drawCtx.vertices)
{
var numVertices = (drawCtx.vertices.length / 4);
vertexBuffer.setData(drawCtx.vertices, 0, numVertices);
}
Text drawing parameters.
Defaults to left-aligned.
Returns a rendering context object containing internal information including an array of vertex data. The context object can be passed into drawTextVertices. The context has the following property:
- vertices
An array of numbers, 4 numbers per vertex: X, Y, U, V.
SDK 0.28.0 onwards the vertex order is: top left, top right, bottom left, bottom right
Prior to SDK 0.28.0 the vertex order was: top left, top right, bottom right, bottom left
Summary
Draws the given text vertices for a specific texture page. This method is used internally by drawTextRect to draw the vertices generated by generateTextVertices.
Syntax
var textParameters = {
rect: [x, y, width, height],
alignment: windowdef.textalign,
scale: windowdef.textscale,
spacing: windowdef.textspacing,
};
var vertices = font.generatePageTextVertices(text, textParameters, 0);
if (vertices)
{
var numValues = vertices.length;
var n;
for (n = 0; n < numValues; n += 4)
{
var p = transformPoint(vertices[n], vertices[n + 1]);
vertices[n] = p[0];
vertices[n + 1] = p[1];
}
font.drawTextVertices(vertices, 0, reuse);
}
Summary
Draws text.
Syntax
graphicsDevice.setTechnique(textTechnique);
var textParameters = {
rect: [x, y, width, height],
alignment: windowdef.textalign,
scale: windowdef.textscale,
spacing: windowdef.textspacing,
lineSpacing: windowdef.linespacing
};
if (dimensions)
{
textParameters.dimensions = dimensions;
}
font.drawTextRect(text, textParameters);
Text drawing parameters.
Defaults to left-aligned.