Text#Text

new Text(game, x, y, text, style)

Create a new game object for displaying Text.

This uses a local hidden Canvas object and renders the type into it. It then makes a texture from this for rendering to the view.
Because of this you can only display fonts that are currently loaded and available to the browser: fonts must be pre-loaded.

See this compatibility table for the available default fonts across mobile browsers.

Parameters
Name Type Argument Description
game Phaser.Game

Current game instance.

x number

X position of the new text object.

y number

Y position of the new text object.

text string

The actual text that will be written.

style object <optional>

The style properties to be set on the Text.

Properties
Name Type Argument Default Description
font string <optional>
'bold 20pt Arial'

The style and size of the font.

fontStyle string <optional>
(from font)

The style of the font (eg. 'italic'): overrides the value in style.font.

fontVariant string <optional>
(from font)

The variant of the font (eg. 'small-caps'): overrides the value in style.font.

fontWeight string <optional>
(from font)

The weight of the font (eg. 'bold'): overrides the value in style.font.

fontSize string | number <optional>
(from font)

The size of the font (eg. 32 or '32px'): overrides the value in style.font.

backgroundColor string <optional>
null

A canvas fillstyle that will be used as the background for the whole Text object. Set to null to disable.

fill string <optional>
'black'

A canvas fillstyle that will be used on the text eg 'red', '#00FF00'.

align string <optional>
'left'

Horizontal alignment of each line in multiline text. Can be: 'left', 'center' or 'right'. Does not affect single lines of text (see textBounds and boundsAlignH for that).

boundsAlignH string <optional>
'left'

Horizontal alignment of the text within the textBounds. Can be: 'left', 'center' or 'right'.

boundsAlignV string <optional>
'top'

Vertical alignment of the text within the textBounds. Can be: 'top', 'middle' or 'bottom'.

stroke string <optional>
'black'

A canvas stroke style that will be used on the text stroke eg 'blue', '#FCFF00'.

strokeThickness number <optional>
0

A number that represents the thickness of the stroke. Default is 0 (no stroke).

wordWrap boolean <optional>
false

Indicates if word wrap should be used.

wordWrapWidth number <optional>
100

The width in pixels at which text will wrap.

maxLines number <optional>
0

The maximum number of lines to be shown for wrapped text.

tabs number <optional>
0

The size (in pixels) of the tabs, for when text includes tab characters. 0 disables. Can be an array of varying tab sizes, one per tab stop.

Source code: gameobjects/Text.js (Line 40)
doc_phaser
2017-02-14 11:14:38
Comments
Leave a Comment

Please login to continue.