mwg API
    Preparing search index...

    Function createLayers

    • Creates one labeled Node2D per name, attached to parent in the order given, and returns them keyed by name. A game with a dozen conventionally-ordered layers (terrain, units, effects, UI, ...) otherwise hand-wires each one and adds them in the right order everywhere; this is that boilerplate once. The names and their order stay the caller's own convention - nothing here decides what a layer is called or which should draw on top.

      Parameters

      • parent: Container
      • names: readonly string[]

      Returns Record<string, Node2D>

      import { Node2D, createLayers, Sprite2D } from '@datamoc/mw_games/two-d/render';

      const stage = new Node2D();
      const layers = createLayers(stage, ['terrain', 'units', 'effects', 'ui']);
      layers.units.addChild(new Sprite2D());
      console.log(layers.effects.label); // 'effects'