0:01 / 0:30
Playback speed

Sprite sheet

Pause the walk. Match the feet on the right to the highlighted cell on the left.

#SpritesAndImages#Sprite

One image file holding every frame of an animation, laid out in a grid.

Instead of loading a separate file for each pose, the game loads one sheet and shows one cell at a time. Stepping through the cells quickly makes the character move.

Code

src/demos/sprite_sheet.goose
namespace sprite_sheet_lesson;
import stage;
import std;
import math;

export "sprite-sheet" fn draw(time: f64, dt: f64, px: f64, py: f64, hover: bool) {
    artwork("draft");
    let frame = (time * 6) as i64 % 4;
    checker(12, 22, 56, 56, 7);
    for i in 4 {
        let x = 12 + (i % 2) * 28;
        let y = 22 + (i / 2) * 28;
        image(i, x + 2, y + 2, 2);
        box(x, y, 28, 28, LINE);
    }
    box(12 + (frame % 2) * 28, 22 + (frame / 2) * 28, 28, 28, MAG);
    rect(76, 49, 10, 2, WHITE);
    quad(86, 46, 91, 50, 86, 54, 86, 46, WHITE);
    image(frame, 100, 26, 4);
}

Stage drawing helpers · All demos on GitHub

Comments

No comments yet.