Function pickSprite2D
-
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
nullif the point is over no sprite. - layers: readonly Sprite2DLayer[]
Hit-test a point against the sprites of one or more
Sprite2DLayers and return the topmost sprite under it, ornullfor a miss.xPx/yPxare in the layers' local coordinate space — the same space as each sprite'spositionPx. For a layer rendered 1:1 to the canvas (identityview) 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 oflayer.view(the caller owns that transform). Alllayersare 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: falseand hidden sprites (visible: false, stored as a zero-size quad) are skipped, exactly as the renderer skips them.