Client interactions
Register client-only pointer behaviors for map sprites. Use interactions for hover popovers, selection feedback, drag previews, cursor changes, and other CanvasEngine overlays. Nothing is sent to the server unless a behavior callsctx.action(...).
Mental Model
interactions is a client-side layer attached to rendered map sprites. It does
not change gameplay state by itself.
Use it for:
- hover popovers
- selection states
- cursor changes
- local highlights and drag previews
- hitbox-based pointer filtering
- explicit pointer-driven actions
ctx.action(...) and validate the request on the server.
Registering A Behavior
target can be:
- a sprite/event id
- an event name
- a sprite
_type, such as"event"or"player" "*"for every sprite- a function receiving
{ client, target, sprite }
From A Client Module
Useinteractions.setup() when registering behaviors from a module:
interactions.use is also accepted:
Hover Popover
Register a CanvasEngine component as an overlay for an existing event:target/sprite: the RPGJS client spritestate:{ hovered, pressed, selected, dragging, data, overlays }bounds: the default visual boundshitboxBounds: the gameplay hitbox boundsgraphicBounds: the rendered graphic boundspointer: the client pointer helperclient: the currentRpgClientEngine
defineProps() are prop accessors.
Read the sprite with sprite() or target() before accessing its fields.
Component bounds are local to the sprite, so bounds() can be used directly to
draw overlays attached to that sprite.
Example:
Client-Only Selection
selectable() stores selection state locally. It does not send an action.
state().selected:
Explicit Server Action
Callctx.action(...) only when the pointer gesture is meant to perform
gameplay. This delegates to engine.processAction(...).
eventId should be treated as intent, not authority.
Hitbox-Based Interactions
UsehitTest() to choose the clickable or draggable area. This is useful when a
sprite graphic is larger than its gameplay body.
Inside handlers and hitTest(), ctx.bounds() returns world-space bounds so it
can be compared directly with ctx.pointer.world().
ctx.bounds('hitbox'): RPGJS gameplay hitboxctx.bounds('graphic'): rendered graphic boundsctx.bounds(): default bounds, currently graphic-first
Drag And Drop To A Tile
dragToTile() starts a local drag state and sends an action on drop.
ctx.pointer.tile() returns:
data:
Custom Drag Preview
For full control, use low-level handlers:DOMContainer, Graphics, Sprite, or Text.
Low-Level Behavior API
A behavior can define these handlers:pointerenterpointerleavepointeroverpointeroutpointerdownpointeruppointermoveclickdragstartdragmovedropcancel
Interaction Context
Every handler receivesctx:
Helpers
RPGJS exports small helpers for common cases:engine.interactions.use(...).
Network Rules
- Pointer movement, hover, overlays, selection, drag previews, and cursor changes are client-only.
ctx.overlay.*,ctx.state.*, andctx.select()do not send packets.ctx.action(...)is the only interaction helper that sends an action to the server.- Server code must validate distance, permissions, target visibility, and map state before applying gameplay changes.