Talos docs

SpriteAnimationEndEvent

Since 0.6

data of the event a non-looping sprite animation raises when it ends.

Plain text

Signature

export interface SpriteAnimationEndEvent {
  /** Id of the entity whose sprite it was. */
  entity: string
  /** The animation that ended. */
  animation: string
  /** The animation that took over (`then`), or null. */
  next: string | null
}

Import: import type { SpriteAnimationEndEvent } from "@argus/api"

Members

MemberSignatureDescription
entityentity: stringId of the entity whose sprite it was.
animationanimation: stringThe animation that ended.
nextnext: string | nullThe animation that took over (then), or null.

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>