SpriteFrameEvent
Since next
data of a bus event an animation's events entry raises.
Signature
export interface SpriteFrameEvent {
/** Id of the entity whose sprite it was. */
entity: string
/** The animation playing. */
animation: string
/** The entry of the animation's `frames` that started to show. */
frame: number
}
Import: import type { SpriteFrameEvent } from "@argus/api"
Members
| Member | Signature | Description |
|---|---|---|
entity | entity: string | Id of the entity whose sprite it was. |
animation | animation: string | The animation playing. |
frame | frame: number | The entry of the animation's frames that started to show. |
Example
The tested fixture fixtures/recipes/drone-search/scenes/behaviors/carrier.ts.
import type { Behavior } from "@argus/api"
/** Moves a kinematic body round `props.path` (world [x, z] points) at `props.speed` m/s, facing where it goes: the
* stand-in for a boat or a truck the drone launches from, and for the contact it looks for. */
interface Props {
path: [number, number][]
speed: number
}
interface State {
next: number
}
export default {
init(ctx) {
ctx.state.next ??= 0
},
update(ctx, dt) {
const path = ctx.props.path
const goal = path[ctx.state.next % path.length]
if (goal === undefined) return
const p = ctx.entity.position
const to: [number, number, number] = [goal[0], p[1], goal[1]]
ctx.entity.lookAt(to)
if (ctx.entity.moveToward(to, ctx.props.speed * dt)) ctx.state.next = (ctx.state.next + 1) % path.length
},
} satisfies Behavior<State, Props>