BitmapText#BitmapText

new BitmapText(game, x, y, font, text, size, align)

BitmapText objects work by taking a texture file and an XML or JSON file that describes the font structure.
It then generates a new Sprite object for each letter of the text, proportionally spaced out and aligned to
match the font structure.

BitmapText objects are less flexible than Text objects, in that they have less features such as shadows, fills and the ability
to use Web Fonts, however you trade this flexibility for rendering speed. You can also create visually compelling BitmapTexts by
processing the font texture in an image editor, applying fills and any other effects required.

To create multi-line text insert \r, \n or \r\n escape codes into the text string.

If you are having performance issues due to the volume of sprites being rendered, and do not require the text to be constantly
updating, you can use BitmapText.generateTexture to create a static texture from this BitmapText.

To create a BitmapText data 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/

For most use cases it is recommended to use XML. If you wish to use JSON, the formatting should be equal to the result of
converting a valid XML file through the popular X2JS library. An online tool for conversion can be found here: http://codebeautify.org/xmltojson

If you were using an older version of Phaser (< 2.4) and using the DOMish parser hack, please remove this. It isn't required any longer.

Parameters
Name Type Argument Default Description
game Phaser.Game

A reference to the currently running game.

x number

X coordinate to display the BitmapText object at.

y number

Y coordinate to display the BitmapText object at.

font string

The key of the BitmapText as stored in Phaser.Cache.

text string <optional>
''

The text that will be rendered. This can also be set later via BitmapText.text.

size number <optional>
32

The size the font will be rendered at in pixels.

align string <optional>
'left'

The alignment of multi-line text. Has no effect if there is only one line of text.

Source code: gameobjects/BitmapText.js (Line 54)
doc_phaser
2017-02-14 10:37:26
Comments
Leave a Comment

Please login to continue.