Skip to content

Kiln API / kiln / animationGraph

Function: animationGraph() ​

ts
function animationGraph<S, P, T>(spec): AnimationGraph;

Defines an animation state graph as data, checked when it is made:

ts
export const HeroAnim = animationGraph({
  initial: 'idle',
  params: { speed: 0 },
  triggers: ['attack'],
  states: { idle: {}, run: { events: [{ frame: 1, name: 'footstep' }] }, attack: { loop: 'once' } },
  transitions: [
    { from: 'idle', to: 'run', when: { speed: { gt: 0.1 } } },
    { from: 'run', to: 'idle', when: { speed: { lte: 0.1 } } },
    { from: '*', to: 'attack', trigger: 'attack' },
    { from: 'attack', to: 'idle', exitTime: 1 },
  ],
})

Type Parameters ​

Type ParameterDefault type
S extends string-
P extends Record<string, number | boolean>object
T extends stringnever

Parameters ​

ParameterType
specAnimationGraphSpec<S, P, T>

Returns ​

AnimationGraph