Skip to main content
Version: Phaser v3.88.2

Types.GameObjects.Text

GetTextSizeObject

<static> GetTextSizeObject

Results object from a call to GetTextSize.

nametypeoptionaldescription
widthnumberNoThe width of the longest line in the Text object.
heightnumberNoThe height of the Text object.
linesnumberNoThe number of lines in the Text object.
lineWidthsArray.<number>NoAn array of the lines for each line in the Text object.
lineSpacingnumberNoThe line spacing of the Text object.
lineHeightnumberNoThe height of a line factoring in font and stroke.

Type: object

Member of: Phaser.Types.GameObjects.Text

Source: src/gameobjects/text/typedefs/GetTextSizeObject.js#L1
Since: 3.0.0


TextConfig

<static> TextConfig

nametypeoptionaldescription
textstring | Array.<string>YesThe text this Text object will display.
stylePhaser.Types.GameObjects.Text.TextStyleYesThe Text style configuration object.
paddingPhaser.Types.GameObjects.Text.TextPaddingYesA Text Padding object.

Type: object

Member of: Phaser.Types.GameObjects.Text

Source: src/gameobjects/text/typedefs/TextConfig.js#L1
Since: 3.0.0


TextMetrics

<static> TextMetrics

Font metrics for a Text Style object.

nametypeoptionaldescription
ascentnumberNoThe ascent of the font.
descentnumberNoThe descent of the font.
fontSizenumberNoThe size of the font.

Type: object

Member of: Phaser.Types.GameObjects.Text

Source: src/gameobjects/text/typedefs/TextMetrics.js#L1
Since: 3.0.0


TextPadding

<static> TextPadding

A Text Padding configuration object as used by the Text Style.

nametypeoptionaldescription
xnumberYesIf set this value is used for both the left and right padding.
ynumberYesIf set this value is used for both the top and bottom padding.
leftnumberYesThe amount of padding added to the left of the Text object.
rightnumberYesThe amount of padding added to the right of the Text object.
topnumberYesThe amount of padding added to the top of the Text object.
bottomnumberYesThe amount of padding added to the bottom of the Text object.

Type: object

Member of: Phaser.Types.GameObjects.Text

Source: src/gameobjects/text/typedefs/TextPadding.js#L1
Since: 3.18.0


TextShadow

<static> TextShadow

A Text Shadow configuration object as used by the Text Style.

nametypeoptionaldefaultdescription
offsetXnumberYes0The horizontal offset of the shadow.
offsetYnumberYes0The vertical offset of the shadow.
colorstringYes"'#000'"The color of the shadow, given as a CSS string value.
blurnumberYes0The amount of blur applied to the shadow. Leave as zero for a hard shadow.
strokebooleanYesfalseApply the shadow to the stroke effect on the Text object?
fillbooleanYesfalseApply the shadow to the fill effect on the Text object?

Type: object

Member of: Phaser.Types.GameObjects.Text

Source: src/gameobjects/text/typedefs/TextShadow.js#L1
Since: 3.0.0


TextStyle

<static> TextStyle

A Text Style configuration object as used by the Text Game Object.

nametypeoptionaldefaultdescription
fontFamilystringYes"'Courier'"The font the Text object will render with. This is a Canvas style font string.
fontSizenumber | stringYes"'16px'"The font size, as a CSS size string.
fontStylestringYesAny addition font styles, such as 'bold'.
fontstringYesThe font family or font settings to set. Overrides the other font settings.
backgroundColorstringYesA solid fill color that is rendered behind the Text object. Given as a CSS string color such as #ff0.
colorstring | CanvasGradientCanvasPatternYes"'#fff'"
strokestring | CanvasGradientCanvasPatternYes"'#fff'"
strokeThicknessnumberYes0The thickness of the stroke around the Text. Set to zero for no stroke.
shadowPhaser.Types.GameObjects.Text.TextShadowYesThe Text shadow configuration object.
paddingPhaser.Types.GameObjects.Text.TextPaddingYesA Text Padding object.
alignstringYes"'left'"The alignment of the Text. This only impacts multi-line text. Either left, right, center or justify.
maxLinesnumberYes0The maximum number of lines to display within the Text object.
fixedWidthnumberYes0Force the Text object to have the exact width specified in this property. Leave as zero for it to change accordingly to content.
fixedHeightnumberYes0Force the Text object to have the exact height specified in this property. Leave as zero for it to change accordingly to content.
resolutionnumberYes0Sets the resolution (DPI setting) of the Text object. Leave at zero for it to use the game resolution.
rtlbooleanYesfalseSet to true if this Text object should render from right-to-left.
testStringstringYes"'|MÉqgy'"This is the string used to aid Canvas in calculating the height of the font.
baselineXnumberYes1.2The amount of horizontal padding added to the width of the text when calculating the font metrics.
baselineYnumberYes1.4The amount of vertical padding added to the height of the text when calculating the font metrics.
wordWrapPhaser.Types.GameObjects.Text.TextWordWrapYesThe Text Word wrap configuration object.
metricsPhaser.Types.GameObjects.Text.TextMetricsYesA Text Metrics object. Use this to avoid expensive font size calculations in text heavy games.
lineSpacingnumberYesThe amount to add to the font height to achieve the overall line height.
letterSpacingnumberYesThe amount to add to the spacing between characters. Can be a negative or positive number.

Type: object

Member of: Phaser.Types.GameObjects.Text

Source: src/gameobjects/text/typedefs/TextStyle.js#L1
Since: 3.0.0


TextWordWrap

<static> TextWordWrap

A Text Word Wrap configuration object as used by the Text Style configuration.

nametypeoptionaldefaultdescription
widthnumberYesThe width at which text should be considered for word-wrapping.
callbackTextStyleWordWrapCallbackYesProvide a custom callback when word wrapping is enabled.
callbackScopeanyYesThe context in which the word wrap callback is invoked.
useAdvancedWrapbooleanYesfalseUse basic or advanced word wrapping?

Type: object

Member of: Phaser.Types.GameObjects.Text

Source: src/gameobjects/text/typedefs/TextWordWrap.js#L1
Since: 3.0.0