Skip to content

[Feature] Sprite frame animation #158

@vmarcella

Description

@vmarcella

Overview

Add frame-based animation for 2D sprites using sprite sheet sequences.

Current State

No response

Scope

Goals:

  • Define animation clips (frame sequence, timing)
  • Play/pause/stop animation
  • Configurable frame rate
  • Loop and ping-pong modes
  • Animation events (on frame, on complete)

Non-Goals:

  • Skeletal 2D animation
  • Sprite atlas management

Proposed API

pub struct SpriteAnimation {
  frames: Vec<SpriteFrame>,
  frame_duration: f32,
  current_frame: usize,
  elapsed: f32,
  mode: AnimationMode,
  playing: bool,
}

pub struct SpriteFrame {
  pub uv_min: [f32; 2],
  pub uv_max: [f32; 2],
}

pub enum AnimationMode {
  Once,
  Loop,
  PingPong,
}

impl SpriteAnimation {
  pub fn new(frames: Vec<SpriteFrame>, fps: f32) -> Self;
  pub fn with_mode(self, mode: AnimationMode) -> Self;
  pub fn play(&mut self);
  pub fn pause(&mut self);
  pub fn stop(&mut self);
  pub fn update(&mut self, dt: f32) -> bool; // true if frame changed
  pub fn current_frame(&self) -> &SpriteFrame;
  pub fn is_finished(&self) -> bool;
}

Acceptance Criteria

  • Frames advance at specified rate
  • Loop mode repeats indefinitely
  • Once mode stops at last frame
  • PingPong reverses at ends
  • Frame UVs usable for rendering

Affected Crates

lambda-rs

Notes

  • Integrate with sprite/2D rendering system
  • Consider animation definition format (JSON/RON)

Metadata

Metadata

Assignees

No one assigned

    Labels

    animationAll things related to animationsenhancementNew feature or requestlambda-rsIssues pertaining to the core framework

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions