pixi.js
    Preparing search index...

    Class TextStyle

    A TextStyle Object contains information to decorate Text objects. An instance can be shared between multiple Text objects; then changing the style will update all text objects using it.

    // Create a basic text style
    const style = new TextStyle({
    fontFamily: ['Helvetica', 'Arial', 'sans-serif'],
    fontSize: 36,
    fill: 0xff1010,
    align: 'center'
    });

    // Create a rich text style with multiple features
    const richStyle = new TextStyle({
    fontFamily: 'Arial',
    fontSize: 32,
    fill: ['#FF0000', '#00FF00'], // Gradient fill
    stroke: {
    color: '#4a1850',
    width: 5
    },
    dropShadow: {
    color: '#000000',
    blur: 4,
    distance: 6,
    angle: Math.PI / 6
    },
    wordWrap: true,
    wordWrapWidth: 440,
    lineHeight: 40,
    align: 'center'
    });

    // Share style between multiple text objects
    const text1 = new Text({
    text: 'Hello',
    style: richStyle
    });

    const text2 = new Text({
    text: 'World',
    style: richStyle
    });

    // Update style dynamically - affects all text objects
    richStyle.fontSize = 48;
    richStyle.fill = 0x00ff00;

    Key Features:

    • Shared styling between multiple text objects
    • Rich text formatting options
    • Gradient and pattern fills
    • Drop shadows and strokes
    • Word wrapping and alignment
    • Dynamic updates

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    defaultDropShadow: TextDropShadow = ...

    Default drop shadow settings used when enabling drop shadows on text. These values are used as the base configuration when drop shadows are enabled without specific settings.

    // Customize default settings globally
    TextStyle.defaultDropShadow.alpha = 0.5; // 50% opacity for all shadows
    TextStyle.defaultDropShadow.blur = 2; // 2px blur for all shadows
    TextStyle.defaultDropShadow.color = 'blue'; // Blue shadows by default
    defaultTextStyle: TextStyleOptions = ...

    Default text style settings used when creating new text objects. These values serve as the base configuration and can be customized globally.

    // Customize default text style globally
    TextStyle.defaultTextStyle.fontSize = 16;
    TextStyle.defaultTextStyle.fill = 0x333333;
    TextStyle.defaultTextStyle.fontFamily = ['Arial', 'Helvetica', 'sans-serif'];

    Accessors

    • get breakWords(): boolean

      Indicates if lines can be wrapped within words, it needs wordWrap to be set to true.

      Returns boolean

    • set breakWords(value: boolean): void

      Parameters

      • value: boolean

      Returns void

    • get fill(): FillInput

      The fill style that will be used to color the text. This can be:

      • A color string like 'red', '#00FF00', or 'rgba(255,0,0,0.5)'
      • A hex number like 0xff0000 for red
      • A FillStyle object with properties like { color: 0xff0000, alpha: 0.5 }
      • A FillGradient for gradient fills
      • A FillPattern for pattern/texture fills

      When using a FillGradient, vertical gradients (angle of 90 degrees) are applied per line of text, while gradients at any other angle are spread across the entire text body as a whole.

      Returns FillInput

      // Vertical gradient applied per line
      const verticalGradient = new FillGradient(0, 0, 0, 1)
      .addColorStop(0, 0xff0000)
      .addColorStop(1, 0x0000ff);

      const text = new Text({
      text: 'Line 1\nLine 2',
      style: { fill: verticalGradient }
      });

      To manage the gradient in a global scope, set the textureSpace property of the FillGradient to 'global'.
    • set fill(value: FillInput): void

      Parameters

      Returns void

    • get filters(): Filter[]

      An optional filter or array of filters to apply to the text, allowing for advanced visual effects. These filters will be applied to the text as it is created, resulting in faster rendering for static text compared to applying the filter directly to the text object (which would be applied at run time).

      Returns Filter[]

      null
      
    • set filters(value: Filter[]): void

      Parameters

      Returns void

    • get fontFamily(): string | string[]

      The font family, can be a single font name, or a list of names where the first is the preferred font.

      Returns string | string[]

    • set fontFamily(value: string | string[]): void

      Parameters

      • value: string | string[]

      Returns void

    • get fontSize(): number

      The font size (as a number it converts to px, but as a string, equivalents are '26px','20pt','160%' or '1.6em')

      Returns number

    • set fontSize(value: string | number): void

      Parameters

      • value: string | number

      Returns void

    • get leading(): number

      The space between lines.

      Returns number

    • set leading(value: number): void

      Parameters

      • value: number

      Returns void

    • get letterSpacing(): number

      The amount of spacing between letters, default is 0.

      Returns number

    • set letterSpacing(value: number): void

      Parameters

      • value: number

      Returns void

    • get lineHeight(): number

      The line height, a number that represents the vertical space that a letter uses.

      Returns number

    • set lineHeight(value: number): void

      Parameters

      • value: number

      Returns void

    • get padding(): number

      Occasionally some fonts are cropped. Adding some padding will prevent this from happening by adding padding to all sides of the text.

      Note

      This will NOT affect the positioning or bounds of the text.

      Returns number

    • set padding(value: number): void

      Parameters

      • value: number

      Returns void

    • get trim(): boolean

      Trim transparent borders from the text texture.

      Important

      PERFORMANCE WARNING: This is a costly operation as it requires scanning pixel alpha values. Avoid using trim: true for dynamic text, as it could significantly impact performance.

      Returns boolean

    • set trim(value: boolean): void

      Parameters

      • value: boolean

      Returns void

    • get wordWrap(): boolean

      Indicates if word wrap should be used.

      Returns boolean

    • set wordWrap(value: boolean): void

      Parameters

      • value: boolean

      Returns void

    • get wordWrapWidth(): number

      The width at which text will wrap, it needs wordWrap to be set to true.

      Returns number

    • set wordWrapWidth(value: number): void

      Parameters

      • value: number

      Returns void

    Methods

    • Creates a new TextStyle object with the same values as this one.

      Returns TextStyle

      New cloned TextStyle object

    • Destroys this text style.

      Parameters

      Returns void

      // Destroy the text style and its textures
      textStyle.destroy({ texture: true, textureSource: true });
      textStyle.destroy(true);
    • Resets all properties to the default values

      Returns void

    • Returns void