mwg API
    Preparing search index...

    Class Label

    A piece of text, styled from the theme.

    This is a thin wrapper over Pixi's Text, and its job is to stop every call site from repeating a style object. Pixi renders text to its own texture, so changing the string costs a re-render: cheap enough for a label, wasteful for something updated every frame, where a value that only changes on whole numbers should be guarded.

    import { Label } from '@datamoc/mw_games/two-d/ui';

    const gold = new Label({ text: 'Gold: 0', color: 0xffe680 });

    gold.setText('Gold: 50'); // skips the re-render if the string is unchanged
    gold.setColor(0xff4444); // flash red on a loss, say

    Hierarchy

    • Text
      • Label
    Index
    • Destroys this text renderable and optionally its style texture.

      Parameters

      • Optionaloptions: DestroyOptions

        Options parameter. A boolean will act as if all options have been set to that value

      Returns void

      // Destroys the text and its style
      text.destroy({ style: true, texture: true, textureSource: true });
      text.destroy(true);
      text.destroy() // Destroys the text, but not its style
    • changes the colour without rebuilding the style object

      Parameters

      • color: number

      Returns void

    • avoids the re-render when the text has not actually changed

      Parameters

      • value: string

      Returns void

    • Shows value progressively, speed characters per second. The game drives the reveal by calling updateReveal(dt) each frame (a label owns no update loop of its own, unlike a MessageBox on a WindowStack); completeReveal skips to the end, for a confirm press mid-reveal.

      Parameters

      • value: string
      • Optionalspeed: number

      Returns void

    • advances an in-progress reveal; returns true when nothing is left to show

      Parameters

      • dt: number

      Returns boolean