mwg API
    Preparing search index...

    Class Bar

    A filled proportion of a track - a health, mana or experience bar.

    Closer to a small, focused primitive than a general-purpose progress-bar widget: it draws a background track and a foreground fill sized to value / max, and nothing else. Colour follows the theme the way Label does, unless a game gives one of its own.

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

    const hp = new Bar({ width: 120, height: 8, color: 0xcc3333, value: 30, max: 30 });

    hp.setValue(18, 30); // took damage
    console.log(hp.value); // 0.6
    hp.setColor(0xff0000); // and it is bleeding

    hp.resize(160, 8); // the window around it grew

    Hierarchy

    • Container
      • Bar
    Index
    • get background(): number

      the resolved track colour: background, or the theme's panel fill

      Returns number

    • get color(): number

      the resolved fill colour: the explicit one, or the theme's highlight

      Returns number

    • Removes all internal references and listeners as well as removes children from the display list. Do not use a Container after calling destroy.

      Parameters

      • Optionaloptions: DestroyOptions

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

      Returns void

      container.destroy();
      container.destroy(true);
      container.destroy({ children: true });
      container.destroy({ children: true, texture: true, textureSource: true });
    • Parameters

      • width: number
      • height: number

      Returns void

    • Recolours the fill at runtime - the other half of what a bar does on screen, beside setValue: a health bar going red as it empties, a boss bar while it bleeds.

      Counts as explicit, exactly as passing color to the constructor does, so a later theme change cannot throw the game's own colour away.

      Parameters

      • color: number

      Returns void

    • Parameters

      • value: number
      • max: number = 1

      Returns void