mwg API
    Preparing search index...

    Class SpriteGroup

    A crowd that only animates its on-screen members.

    TileMap.cull(camera) keeps tile rendering cost to what is on screen; this is the same idea for per-frame animation cost. A scene with hundreds of animated inhabitants calls group.update(camera, dt) once per frame instead of updating each sprite itself, and members outside camera.view (plus margin) simply keep whatever frame they had until they come back into view. Skipped members are never touched: no paused flag is set, no state is rewritten, so a sprite that leaves the group animates exactly as before.

    Members are positioned in the camera's own world units, the way GridMover and TileMap.tileCenter already place things: direct children of camera.world, or anything else whose x/y already read as world coordinates. Members nested deeper (a sword in a hero's hand) report their local position, so they belong to no group, or to one updated unconditionally.

    import { SpriteGroup, AnimatedSprite, Camera } from '@datamoc/mwg/two-d/render';

    declare const camera: Camera;

    const crowd = new SpriteGroup();
    const goblin = new AnimatedSprite();
    crowd.add(goblin);

    function onFrame(dt: number): void {
    crowd.update(camera, dt); // goblins off screen keep their frame, for free
    }
    Index
    • Advances every member on screen by dt, skipping the rest. margin grows the tested box the way isOnScreen's does, for members larger than a point.

      Parameters

      • camera: Camera
      • dt: number
      • margin: number = 0

      Returns void