API

Function pickSprite2D

  • Hit-test a point against the sprites of one or more Sprite2DLayers and return the topmost sprite under it, or null for a miss.

    xPx / yPx are in the layers' local coordinate space — the same space as each sprite's positionPx. For a layer rendered 1:1 to the canvas (identity view) that is simply the backing-store pixel under the pointer ((clientX - rect.left) * devicePixelRatio). For a panned / zoomed / rotated layer, map the pointer into layer space first via the inverse of layer.view (the caller owns that transform). All layers are assumed to share one space.

    Layers are tested in reverse array order (later layers are drawn on top, so they win). Within an ordinary layer, sprites are tested in reverse canonical logical order (normally reverse insertion order), matching its GPU upload. Within an enabled Y-sort layer, sprites are tested from topmost to bottommost through the current stable draw permutation. Layers with visible: false and hidden sprites (visible: false, stored as a zero-size quad) are skipped, exactly as the renderer skips them.

    Parameters

    • layers: readonly Sprite2DLayer[]

      Sprite layers to test, in draw order (e.g. spriteRenderer.layers).

    • xPx: number

      Query X in layer-local pixels.

    • yPx: number

      Query Y in layer-local pixels.

    Returns SpritePickInfo | null

    The topmost hit, or null if the point is over no sprite.