mwg API
    Preparing search index...

    Class Halo

    The glow around a unit, an aura, a shrine's light: an animated sprite that follows a target and is drawn additively.

    It is an AnimatedSprite, so frames may carry their own durations and offsets, and update(dt) advances it exactly as it advances any other animation. Two things are its own: follow, which applies the halo's offset once rather than in every game that draws one, and the blend mode.

    Z-order is the caller's, and that is not an oversight: a halo that should sit behind its unit is added before it (container.addChild(glow, glow2, unit)), and one that should sit in front is added after. A framework that guessed would be wrong half the time, and a game that wants the glow to be part of the unit's own rotation adds it to the unit instead.

    import { Halo, HALO_ANIMATION, SpriteSheet } from '@datamoc/mw_games/two-d/render';

    declare const sheet: SpriteSheet;
    declare const unit: { x: number; y: number };

    const glow = new Halo({ frames: sheet.range(20, 22), animation: { fps: 6 }, offsetY: -6 });
    glow.follow(unit.x, unit.y);
    glow.update(1 / 60);
    console.log(glow.playing === HALO_ANIMATION); // true - a halo is always playing its own cycle

    Hierarchy (View Summary)

    Index
    onFinish: ((name: string) => void) | null = null

    fires once when a non-looping animation reaches its last frame

    paused: boolean = false
    • get colorAdd(): number

      the packed additive colour; use setColorAdd or lerpTint rather than setting it raw

      Returns number

    • set colorAdd(value: number): void

      Parameters

      • value: number

      Returns void

    • get elapsedTime(): number

      how long the current animation has been running, startTime and all

      Returns number

    • get frameOffset(): { x: number; y: number }

      Where the current frame is drawn relative to the sprite's own position, in pixels. The caller adds it, as in sprite.position.set(x + sprite.frameOffset.x, y + sprite.frameOffset.y). Both are zero for a frame with no offset of its own.

      Returns { x: number; y: number }

    • Puts the halo where its target stands, with whatever offset it was built with. Call it whenever the target moves, or every frame - the halo's own position is never touched by its animation.

      Parameters

      • x: number
      • y: number

      Returns this

    • Moves the sprite strength of the way towards color, leaving its shading intact.

      This sets both halves of the transform: the tint carries 1 - strength and the additive term carries color × strength.

      Parameters

      • color: number
      • strength: number

      Returns void

    • Starts an animation.

      Playing the one already running does nothing, so a movement loop can call play('walk') every frame without restarting it. Pass restart to force it.

      Parameters

      • name: string
      • restart: boolean = false

      Returns this