ecspresso
    Preparing search index...

    Function createSelectionPlugin

    • Create a selection plugin for ECSpresso.

      Provides:

      • Box-drag selection (left-click drag to select multiple entities)
      • Click selection (left-click to select a single entity)
      • Visual feedback (configurable sprite tint for selected entities)
      • Selection box overlay (rendered as a PixiJS Graphics entity)
      • Automatic camera-awareness when cameraState resource is present

      Requires the input plugin and renderer2D plugin to be installed.

      Type Parameters

      • G extends string = "selection"

      Parameters

      Returns Plugin<
          WithResources<
              WithComponents<EmptyConfig, SelectionComponentTypes>,
              SelectionResourceTypes,
          >,
          SelectionRequires,
          "selection-input" | "selection-visual",
          G,
          never,
          never,
      >

      const ecs = ECSpresso.create()
      .withPlugin(createRenderer2DPlugin({ renderLayers: ['game', 'ui'] }))
      .withPlugin(createInputPlugin())
      .withPlugin(createSelectionPlugin({ renderLayer: 'ui' }))
      .build();

      await ecs.initialize();

      ecs.spawn({
      sprite,
      ...createTransform(100, 200),
      ...createSelectable(),
      });