Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Animation

GoudEngine provides three animation systems: sprite animation, state machine controllers, and standalone tweening.

Sprite Animation

AnimationClip

Defines a sequence of frames from a sprite sheet.

FieldTypeDescription
framesVec<Rect>Source rectangles in the sprite sheet
frame_durationf32Seconds per frame
modePlaybackModeLoop or OneShot
eventsVec<AnimationEvent>Events triggered at specific frames

SpriteAnimator

Attach SpriteAnimator to an entity to drive frame-by-frame animation. It updates the entity’s Sprite source rectangle each frame based on the active clip.

FieldTypeDescription
clipAnimationClipActive animation clip
current_frameusizeCurrent frame index
elapsedf32Time since last frame change
playingboolWhether animation is advancing
finishedboolTrue when a OneShot clip reaches its last frame

Animation Events

AnimationEvent fires when the animator reaches a specific frame. Events carry an EventPayload for passing data to event handlers.

Animation Controller

A state machine that manages transitions between animation states.

States and Transitions

Each state holds an AnimationClip. Transitions between states are triggered by parameter conditions:

  • BoolEquals { param, value } — transition when a bool parameter matches
  • FloatGreaterThan { param, threshold } — transition when a float exceeds a threshold
  • FloatLessThan { param, threshold } — transition when a float is below a threshold

Parameters are set externally (from game logic) and the controller evaluates transitions each frame.

Blend Duration

Transitions can specify a blend_duration for smooth crossfading between states. During blending, both the outgoing and incoming clips contribute to the final frame.

Animation Layers

AnimationLayerStack supports multiple animation layers with independent clips and blend weights.

FieldTypeDescription
nameStringLayer identifier
weightf32Blend weight (0.0–1.0)
blend_modeBlendModeOverride or Additive
  • Override: higher layers replace lower layers, scaled by weight
  • Additive: layer output is added to layers below

Tweening

Standalone tween functions interpolate values over time with easing:

EasingDescription
LinearConstant speed
EaseInStarts slow, accelerates
EaseOutStarts fast, decelerates
EaseInOutSlow start and end
EaseInBackOvershoots before settling
EaseOutBounceBounces at the end

FFI

Animation FFI is in goud_engine/src/ffi/animation/:

  • goud_animation_controller_*() — state machine operations
  • goud_animation_layer_*() — layer stack management
  • goud_tween_create() / goud_tween_update() — tween lifecycle