phaser - v4.0.0-rc.4
    Preparing search index...

    A TextStyle class manages all of the style settings for a Text object.

    Text Game Objects create a TextStyle instance automatically, which is accessed via the Text.style property. You do not normally need to instantiate one yourself.

    Index

    Constructors

    Properties

    align: string

    The text alignment.

    backgroundColor: string

    The background color.

    baselineX: number

    The amount of horizontal padding added to the width of the text when calculating the font metrics.

    baselineY: number

    The amount of vertical padding added to the height of the text when calculating the font metrics.

    color: string | CanvasGradient | CanvasPattern

    The text fill color.

    fixedHeight: number

    The fixed height of the text.

    0 means no fixed height.

    fixedWidth: number

    The fixed width of the text.

    0 means no fixed with.

    fontFamily: string

    The font family.

    fontSize: string | number

    The font size.

    fontStyle: string

    The font style.

    maxLines: number

    The maximum number of lines to draw.

    The Text object that this TextStyle is styling.

    resolution: number

    The resolution the text is rendered to its internal canvas at. The default is 0, which means it will use the resolution set in the Game Config.

    rtl: boolean

    Whether the text should render right to left.

    shadowBlur: number

    The shadow blur radius.

    shadowColor: string

    The shadow color.

    shadowFill: boolean

    Whether shadow fill is enabled or not.

    shadowOffsetX: number

    The horizontal shadow offset.

    shadowOffsetY: number

    The vertical shadow offset.

    shadowStroke: boolean

    Whether shadow stroke is enabled or not.

    stroke: string | CanvasGradient | CanvasPattern

    The text stroke color.

    strokeThickness: number

    The text stroke thickness.

    testString: string

    The test string to use when measuring the font.

    wordWrapCallback: TextStyleWordWrapCallback

    A custom function that will be responsible for wrapping the text. It will receive two arguments: text (the string to wrap), textObject (this Text instance). It should return the wrapped lines either as an array of lines or as a string with newline characters in place to indicate where breaks should happen. Setting this directly will not re-run the word wrapping algorithm. To change the callback and re-wrap, use Phaser.GameObjects.TextStyle#setWordWrapCallback.

    wordWrapCallbackScope: object

    The scope that will be applied when the wordWrapCallback is invoked. Setting this directly will not re-run the word wrapping algorithm. To change the callback and re-wrap, use Phaser.GameObjects.TextStyle#setWordWrapCallback.

    wordWrapUseAdvanced: boolean

    Whether or not to use the advanced wrapping algorithm. If true, spaces are collapsed and whitespace is trimmed from lines. If false, spaces and whitespace are left as is. Setting this property directly will not re-run the word wrapping algorithm. To change the advanced setting and re-wrap, use Phaser.GameObjects.TextStyle#setWordWrapWidth.

    wordWrapWidth: number

    The maximum width of a line of text in pixels. Null means no line wrapping. Setting this property directly will not re-run the word wrapping algorithm. To change the width and re-wrap, use Phaser.GameObjects.TextStyle#setWordWrapWidth.

    Methods

    • Set the alignment of the text in this Text object.

      The argument can be one of: left, right, center or justify.

      Alignment only works if the Text object has more than one line of text.

      Parameters

      • Optionalalign: string

        The text alignment for multi-line text. Default 'left'.

      Returns GameObjects.Text

    • Set a fixed width and height for the text.

      Pass in 0 for either of these parameters to disable fixed width or height respectively.

      Parameters

      • width: number

        The fixed width to set.

      • height: number

        The fixed height to set.

      Returns GameObjects.Text

    • Set the font.

      If a string is given, the font family is set.

      If an object is given, the fontFamily, fontSize and fontStyle properties of that object are set.

      Parameters

      • font: string | object

        The font family or font settings to set.

      • OptionalupdateText: boolean

        Whether to update the text immediately. Default true.

      Returns GameObjects.Text

    • Set the resolution used by the Text object.

      It allows for much clearer text on High DPI devices, at the cost of memory because it uses larger internal Canvas textures for the Text.

      Please use with caution, as the more high res Text you have, the more memory it uses up.

      Parameters

      • value: number

        The resolution for this Text object to use.

      Returns GameObjects.Text

    • Set the shadow settings.

      Calling this method always re-measures the parent Text object, so only call it when you actually change the shadow settings.

      Parameters

      • Optionalx: number

        The horizontal shadow offset. Default 0.

      • Optionaly: number

        The vertical shadow offset. Default 0.

      • Optionalcolor: string

        The shadow color. Default '#000'.

      • Optionalblur: number

        The shadow blur radius. Default 0.

      • OptionalshadowStroke: boolean

        Whether to stroke the shadow. Default false.

      • OptionalshadowFill: boolean

        Whether to fill the shadow. Default true.

      Returns GameObjects.Text

    • Set the stroke settings.

      Parameters

      • color: string | CanvasGradient | CanvasPattern

        The stroke color.

      • thickness: number

        The stroke thickness.

      Returns GameObjects.Text

    • Set a custom callback for wrapping lines.

      Pass in null to remove wrapping by callback.

      Parameters

      • callback: TextStyleWordWrapCallback

        A custom function that will be responsible for wrapping the text. It will receive two arguments: text (the string to wrap), textObject (this Text instance). It should return the wrapped lines either as an array of lines or as a string with newline characters in place to indicate where breaks should happen.

      • Optionalscope: object

        The scope that will be applied when the callback is invoked. Default null.

      Returns GameObjects.Text

    • Set the width (in pixels) to use for wrapping lines.

      Pass in null to remove wrapping by width.

      Parameters

      • width: number

        The maximum width of a line in pixels. Set to null to remove wrapping.

      • OptionaluseAdvancedWrap: boolean

        Whether or not to use the advanced wrapping algorithm. If true, spaces are collapsed and whitespace is trimmed from lines. If false, spaces and whitespace are left as is. Default false.

      Returns GameObjects.Text

    • Synchronize the font settings to the given Canvas Rendering Context.

      Parameters

      • canvas: HTMLCanvasElement

        The Canvas Element.

      • context: CanvasRenderingContext2D

        The Canvas Rendering Context.

      Returns void

    • Synchronize the shadow settings to the given Canvas Rendering Context.

      Parameters

      • context: CanvasRenderingContext2D

        The Canvas Rendering Context.

      • enabled: boolean

        Whether shadows are enabled or not.

      Returns void

    • Synchronize the text style settings to the given Canvas Rendering Context.

      Parameters

      • canvas: HTMLCanvasElement

        The Canvas Element.

      • context: CanvasRenderingContext2D

        The Canvas Rendering Context.

      Returns void