Loader#bitmapFont()

bitmapFont(key, textureURL, atlasURL, atlasData, xSpacing, ySpacing) → {Phaser.Loader}

Adds Bitmap Font files to the current load queue.

To create the Bitmap Font files you can use:

BMFont (Windows, free): http://www.angelcode.com/products/bmfont/
Glyph Designer (OS X, commercial): http://www.71squared.com/en/glyphdesigner
Littera (Web-based, free): http://kvazars.com/littera/

You can choose to either load the data externally, by providing a URL to an xml file.
Or you can pass in an XML object or String via the xmlData parameter.
If you pass a String the data is automatically run through Loader.parseXML and then immediately added to the Phaser.Cache.

If URLs are provided the files are not loaded immediately after calling this method, but are added to the load queue.

The key must be a unique String. It is used to add the file to the Phaser.Cache upon successful load.

Retrieve the file via Cache.getBitmapFont(key). XML files are automatically parsed upon load.
If you need to control when the XML is parsed then use Loader.text instead and parse the XML file as needed.

The URLs can be relative or absolute. If the URL is relative the Loader.baseURL and Loader.path values will be prepended to it.

If the textureURL isn't specified then the Loader will take the key and create a filename from that.
For example if the key is "megaFont" and textureURL is null then the Loader will set the URL to be "megaFont.png".
The same is true for the atlasURL. If atlasURL isn't specified and no atlasData has been provided then the Loader will
set the atlasURL to be the key. For example if the key is "megaFont" the atlasURL will be set to "megaFont.xml".

If you do not desire this action then provide URLs and / or a data object.

Parameters
Name Type Argument Default Description
key string

Unique asset key of the bitmap font.

textureURL string

URL of the Bitmap Font texture file. If undefined or null the url will be set to <key>.png, i.e. if key was "megaFont" then the URL will be "megaFont.png".

atlasURL string

URL of the Bitmap Font atlas file (xml/json). If undefined or null AND atlasData is null, the url will be set to <key>.xml, i.e. if key was "megaFont" then the URL will be "megaFont.xml".

atlasData object

An optional Bitmap Font atlas in string form (stringified xml/json).

xSpacing number <optional>
0

If you'd like to add additional horizontal spacing between the characters then set the pixel value here.

ySpacing number <optional>
0

If you'd like to add additional vertical spacing between the lines then set the pixel value here.

Returns

This Loader instance.

Source code: loader/Loader.js (Line 1307)
doc_phaser
2017-02-14 10:54:19
Comments
Leave a Comment

Please login to continue.