ActionBinding
Since 0.6
What one action is bound to right now, in the shape meta.input writes it.
Signature
export interface ActionBinding {
kind: "axis2" | "axis1" | "button"
/**
* Key names. `axis2` takes four in WASD order (+y, -x, -y, +x: up, left, down, right); `axis1`
* two, negative then positive (`["A", "D"]` reads -1 on A, +1 on D); `button` any number, OR'd.
* An axis takes alternate sets back to back, any of which drives it: `["A", "D", "Left",
* "Right"]` for steering on A/D and the arrows, `["W", "A", "S", "D", "Up", "Left", "Down",
* "Right"]` for moving on both. A count that is not a whole number of sets binds nothing.
*/
keys: string[]
mouse: MouseBinding | null
gamepad: GamepadBinding | null
}
Import: import type { ActionBinding } from "@argus/api"
Members
| Member | Signature | Description |
|---|---|---|
kind | kind: "axis2" | "axis1" | "button" | |
keys | keys: string[] | Key names. axis2 takes four in WASD order (+y, -x, -y, +x: up, left, down, right); axis1 two, negative then positive (["A", "D"] reads -1 on A, +1 on D); button any number, OR'd. An axis takes alternate sets back to back, any of which drives it: ["A", "D", "Left", "Right"] for steering on A/D and the arrows, ["W", "A", "S", "D", "Up", "Left", "Down", "Right"] for moving on both. A count that is not a whole number of sets binds nothing. |
mouse | mouse: MouseBinding | null | |
gamepad | gamepad: GamepadBinding | null |
Example
The tested fixture fixtures/recipes/jump-pad-and-elevator/scenes/behaviors/camera-zone.ts.
import type { Behavior } from "@argus/api"
/**
* A trigger volume that retunes the camera while the player is inside it.
*
* The engine has no camera-zone concept and needs none: a volume, a `trigger` component and this.
* Here the player's behaviour owns the camera (it re-sends its params when the view is turned), so
* the zone tells it what to change rather than calling `ctx.camera.set` itself. In a scene where
* nothing else writes the camera, the zone can call `ctx.camera.set(kind, params)` directly.
*/
interface Props {
/** `ctx.camera.set` params to merge in on the way in, and on the way out. */
inside?: Record<string, unknown>
outside?: Record<string, unknown>
}
export default {
onTrigger(ctx, trigger) {
const params = trigger.entering ? ctx.props.inside : ctx.props.outside
if (params) ctx.events.emit("camera-zone", { target: trigger.other.id, params })
},
} satisfies Behavior<Record<string, never>, Props>