Hazel

Sprite Animation

Animate a 2D character from sprite sheets: an idle loop, a run cycle, eight walking directions. There is no separate system to learn. A sprite animation is an ordinary clip on the Timeline that steps through the cells of a sheet, played by the same Animator a 3D character uses. The Sprite Anim panel is a quick way to make those clips: you click the frames, and it writes the clip.

How it fits together

  • The sprite's Sprite Image component holds the sheet, and its H Frames and V Frames (in the Sheet group) cut it into a grid of cells. Frame says which cell shows.
  • A clip keys Frame over time, holding each cell until the next. That is the whole flipbook.
  • A character whose actions live in separate sheets (Idle.png, Run.png, ...) keeps them all in one list on the Sprite Image component. Each clip also keys which sheet is showing, so playing idle_s shows the idle sheet and run_s the run sheet.

Making clips

1. Make the sprite

Drag a sprite sheet from the Assets panel into the 2D view. It becomes a sprite where you drop it. Select it. See 2D for working in 2D.

2. Set the grid

In the Inspector's Sprite Image component, open the Sheet group and set H Frames (columns) and V Frames (rows) to match the sheet, for example 8 and 6.

3. Pick the frames

Open the Sprite Anim panel (in the 2D panel group, with a film-strip icon). It shows the selected sprite's sheet with the grid drawn over it.

ToDo
Select a block of cellsLeft-drag a rectangle
Select one cellClick it
Build an exact sequenceCtrl + click cells one at a time, in the order they should play
ZoomMouse wheel (toward the cursor), or the - / + buttons
PanRight-drag

Selected cells are numbered in the order they will play. A dragged rectangle reads left to right, then top to bottom, so a single column plays top to bottom and a single row left to right. For a sheet where each column is a direction, drag one column per clip.

4. Create the clip

Set the FPS (frames per second), type a clip name such as idle_s, and click Create Clip. This:

  • writes animations/idle_s.anim with a key per cell, each held until the next,
  • adds it to the sprite's Animator (adding an Animator if there is none) and makes it the Default clip if there was none yet,
  • opens it on the Timeline.

The name field clears and keeps focus, so you can pick the next cells, type the next name and create again. Repeat for each action and direction.

Several sheets on one character

When a character's actions are in separate files, add them all to the one sprite:

  • Add Sheet on the Sprite Image component is a drop area: drop a sheet on it to add it to the list.
  • Image is a dropdown of the sheets in the list. It picks which one is showing, and it has a key button, so a clip can switch sheets.
  • The Sprite Anim panel has a matching Sheet dropdown. Pick the sheet you want to cut frames from, and the clips you create from then on switch to that sheet when they play.

So the routine is: choose Run.png in Sheet, create all the run_* clips; choose Idle.png, create all the idle_* clips.

Editing and playing

A created clip is an ordinary Timeline clip, so everything on Animating applies:

  • Retime by dragging the frame keys; hold a frame longer by moving the next key away.
  • Preview by scrubbing or pressing play on the Timeline.
  • Add event markers for footsteps or the frame a hit lands.
  • Key other properties alongside the frames, the same way as on any clip.

In the game, the Default clip plays on its own. To switch clips, send a Play command from a Rust script on the sprite. This one runs in four directions with the arrow keys:

use bevy::prelude::*;
use renzora::{AnimationCommand, AnimationCommandQueue, ScriptCtx};

fn update(ctx: &mut ScriptCtx) {
    let me = ctx.entity();
    let Some(keys) = ctx.get_resource::<ButtonInput<KeyCode>>() else { return };

    let clip = if keys.pressed(KeyCode::ArrowUp) {
        "run_n"
    } else if keys.pressed(KeyCode::ArrowDown) {
        "run_s"
    } else if keys.pressed(KeyCode::ArrowLeft) {
        "run_w"
    } else if keys.pressed(KeyCode::ArrowRight) {
        "run_e"
    } else {
        "idle_s"
    };

    if let Some(mut queue) = ctx.get_resource_mut::<AnimationCommandQueue>() {
        queue.push(AnimationCommand::Play {
            entity: me,
            name: clip.into(),
            looping: true,
            speed: 1.0,
        });
    }
}

renzora::script!(update);

Play does nothing when that clip is already playing, so sending it every frame is fine. For more than a handful of clips, a state machine can pick the clip from parameters instead.

Next