Client Visuals
Client visuals let the server trigger a named visual macro while the rendering details live on the client. They do not replace existing APIs such asplaySound(), flash(),
showComponentAnimation(), or sprite animations. They are a lightweight way to
group those existing client-side primitives when one gameplay moment needs
several visual or audio reactions at once.
Why use client visuals?
Without client visuals, a hit may require several server packets:hit is rendered. This keeps visual orchestration close
to the renderer, avoids spreading presentation details through server gameplay
code, and reduces bandwidth when several visual operations should happen
together.
When to prefer client visuals
Use client visuals when:- one gameplay moment triggers multiple visual or audio operations
- the visual sequence is client presentation only
- you want to customize rendering without changing server gameplay code
- you want to reduce several visual packets to one server event
Register a client visual
Register visuals in a client module withclientVisuals:
target,source, andobject, resolved fromtargetId,sourceId, andobjectIdposition, resolved frompositionor{ x, y }data, the serializable payload sent by the serverhelpers, a small wrapper around existing client primitives
target, source, or object instead of the *Id fields
when the payload already contains an object id string. The *Id names are
usually clearer for server payloads.
The first argument passed to helpers.component() is a component animation id.
Register that id in the same client module with componentAnimations, or in
another loaded client module, before using it from clientVisuals.
Trigger from a player
player.clientVisual() sends the visual only to that player’s client:
Trigger from a map
map.clientVisual() broadcasts the visual to all players currently on the map:
Available helpers
target, source, and object are resolved client objects. You can pass them
directly to helpers, or pass an object id string to helpers that accept a target.
If a target cannot be resolved, the helper quietly does nothing.
Use helpers.component(id, target, params) to display a registered component
animation on an object. Use helpers.component(id, position, params) to display
it at a map position:
helpers.animation(target, animationName, options) for sprite animations.
Pass graphic when the animation should use a different graphic, and repeat
when it should play more than once:
Payload rules
The payload sent by the server must be serializable:clientVisuals and send only IDs, numbers,
strings, booleans, arrays, and plain objects.
Complete example
This example registers a hit spark component on the client, groups the spark, flash, hit text, and sound in one client visual, then triggers that visual from server gameplay code.hit visual is presented.