mwg API
    Preparing search index...

    Class FloatingText

    A damage number or a "+1 gold": text that rises and fades over its own lifetime, unlike Label's job of a static, positioned string. This is animation over a label, timed rather than laid out - a game positions one instance per pop-up at the world point it should appear over, then drives it with update(dt) the same way core.Spawner is dt-driven.

    Several pop-ups over one world point at once are FloatingTextStack's job, not this class's.

    import { FloatingText } from '@datamoc/mw_games/two-d/ui';
    import type { Container2D } from '@datamoc/mw_games/two-d/render';

    declare const worldLayer: Container2D;

    const popup = new FloatingText({ text: '-12', color: 0xff4444, hold: 0.5 });
    popup.position.set(64, 96);
    worldLayer.addChild(popup);

    popup.update(0.5); // advance the rise/fade by half a second
    if (popup.finished) console.log('already removed and destroyed itself');

    Hierarchy

    • Container
      • FloatingText
    Index
    • get finished(): boolean

      true once the animation has finished and this container has removed and destroyed itself

      Returns boolean

    • get riseOffset(): number

      How far the animation has lifted the text above where it was placed, in pixels: 0 at the start, negative as it rises, and 0 again under reduced motion. The drawn position is y + riseOffset, while y itself never moves, which is what lets a caller (a stack, a game following a moving creature) place a pop-up that is already animating.

      Returns number

    • Ages the pop-up to at least seconds - what a stack does to the lines it lifts out of the way. floatingTextAgeAtLeast is that arithmetic, and says why it is a floor under the age rather than a subtraction from what is left.

      Parameters

      • seconds: number

      Returns void

    • advances the rise/fade; once complete, removes itself from its parent and destroys itself

      Parameters

      • dt: number

      Returns void