mwg API
    Preparing search index...

    Class FloatingTextStack

    Owns the pop-ups a game spawns over world points: one push per number, one update(dt) to drive them all, and no bookkeeping left to the caller.

    The alternative - every call site constructing, positioning, collecting and destroying its own FloatingText - is where the stacking rule gets forgotten and duplicate numbers land on top of each other, which is the whole reason this exists rather than being left to the game.

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

    declare const worldLayer: Container2D;
    declare const hero: { x: number; y: number };
    declare function update(dt: number): void;

    const popups = new FloatingTextStack();
    worldLayer.addChild(popups);

    popups.push({ text: '-12', x: hero.x, y: hero.y, key: 'hero', color: 0xff4444, hold: 0.5 });
    popups.update(0.25); // half a second's worth of rise and fade over every live pop-up

    Hierarchy

    • Container
      • FloatingTextStack
    Index
    • Parameters

      • Optionaloptions: ContainerOptions<ContainerChild>

      Returns FloatingTextStack

    • Spawns a pop-up at options.x/options.y, lifting the lines already there out of its way.

      The newcomer stays exactly where it was asked to appear; anything sharing its key that it would overlap moves up, newest first, each one measured against the line below it and each nudge costing it a little life - Java's order, so a stack grows upward and self-limits. The decision is floatingTextStackMoves; this method only assigns what that plan says.

      Parameters

      Returns FloatingText

    • drives every live pop-up, then forgets the ones that have finished and removed themselves

      Parameters

      • dt: number

      Returns void