mwg API
    Preparing search index...

    Function attachPointer

    • Pointer input as signals - down, move, drag, up - with positions relative to target and, through toWorld, in world units, so a game does not reach for the renderer's own event system to build a draggable thing. One pointer is tracked at a time (the first to press), which is what a mouse or a single finger is; a second finger is ignored until the first lifts.

      Parameters

      • target: EventTarget & { getBoundingClientRect?: () => { left: number; top: number } }
      • options: PointerOptions = {}

      Returns PointerTracker

      import { Input } from '@datamoc/mwg/core';

      const target = new EventTarget(); // the game's canvas in a browser
      const pointer = Input.attachPointer(target, { dragThreshold: 6 });
      pointer.drag.add((p) => console.log('dragging', p.worldX, p.worldY));
      pointer.up.add((p) => console.log(p.dragged ? 'dropped' : 'clicked'));
      pointer.detach();