OpenSNES
Modern Open-Source SNES Development SDK
Loading...
Searching...
No Matches
main.c File Reference

End-to-end Aseprite sprite pipeline: art + timeline → animated metasprite. More...

#include <snes.h>
#include <snes/anim.h>
#include "res/hero_meta.inc"
#include "res/hero_anim.h"
#include "res/hero.inc"

Macros

#define HERO_X   112
 On-screen X of the metasprite origin (32-wide sprite, centred).
#define HERO_Y   88
 On-screen Y of the metasprite origin (48-tall sprite, centred).
#define VRAM_FONT   0x4000
 BG1 font tiles (4bpp, high VRAM so they clear the OBJ region).
#define VRAM_HERO   0x0000
 4bpp hero tiles (res/hero.pic, converted by the build from res/hero.png)
#define VRAM_TEXT   0x6800
 BG1 text tilemap.

Functions

static void drawLabel (u16 idx)
 Print the label for the currently playing generated clip.
int main (void)
 Entry point: animate the generated metasprite, toggle clips on A.

Variables

static AnimPlayer hero_player = ANIM_PLAYER_INIT
 Animation player driving the hero metasprite.
static const MetaspriteStyle hero_style = { .baseTile = 0, .size = OBJ_SMALL }
 Metasprite pointer table generated by opensnes-sprite sheet (res/hero.png.toml).

Detailed Description

End-to-end Aseprite sprite pipeline: art + timeline → animated metasprite.

This example animates a 32×48 metasprite — Kit — whose every byte of data is machine-generated from an Aseprite export — no hand-authored frame tables, no hand-typed animation clips. It is the working reference for the Aseprite path of opensnes-sprite, one settings file beside each export:

hero.png + hero.png.toml ─ opensnes-sprite sheet → hero.pic/.pal + res/hero_meta.inc (tiles, palette, metasprite pointer table) hero.json + hero.json.toml ─ opensnes-sprite anim → res/hero_anim.h (one AnimClip per Aseprite tag)

The sheet owns the pixels and the metasprite geometry; the anim export owns the timeline (tags, per-frame durations, direction) that indexes it. They meet at the frame value: a clip's frame i selects hero_metasprites[i], resolved inline by animTickMeta().

The export holds eight frames and two tags — walk (frames 0-3, forward loop) and wave (frames 4-7, ping-pong) — with per-frame millisecond durations. opensnes-sprite converted those to ticks and folded the ping-pong into the frame order; press A to toggle between the two generated clips.

SNES Concepts
  • Metasprite composition from multiple OAM entries (oamDrawMetasprite)
  • The anim.h player driving a metasprite via animTickMeta()
  • OBJSEL size mode + OBJ VRAM base for 16×16 hardware sprites
  • Sprite palette at CGRAM 128 (OBJ_CGRAM_BASE)
What to Observe
  • Kit walks in place (4-frame cycle, per-frame timing from the export)
  • Press A: he waves (the ping-pong clip), and A again: back to walking
  • The text label shows which generated clip is playing
Modules Used
console, sprite, dma, text, text4bpp, background, input, anim
See also
sprite.h, anim.h, dma.h, input.h, docs/tools/opensnes-sprite.md

Macro Definition Documentation

◆ HERO_X

#define HERO_X   112

On-screen X of the metasprite origin (32-wide sprite, centred).

◆ HERO_Y

#define HERO_Y   88

On-screen Y of the metasprite origin (48-tall sprite, centred).

◆ VRAM_FONT

#define VRAM_FONT   0x4000

BG1 font tiles (4bpp, high VRAM so they clear the OBJ region).

◆ VRAM_HERO

#define VRAM_HERO   0x0000

4bpp hero tiles (res/hero.pic, converted by the build from res/hero.png)

Hero sprite palette, 16 colours (res/hero.pal)

OBJ VRAM word address for the hero tiles (OBJSEL name base = 0)

◆ VRAM_TEXT

#define VRAM_TEXT   0x6800

BG1 text tilemap.

Function Documentation

◆ drawLabel()

void drawLabel ( u16 idx)
static

Print the label for the currently playing generated clip.

Parameters
idxOne of HERO_ANIM_WALK / HERO_ANIM_WAVE.

◆ main()

int main ( void )

Entry point: animate the generated metasprite, toggle clips on A.

Returns
Never returns (infinite loop).

Variable Documentation

◆ hero_player

AnimPlayer hero_player = ANIM_PLAYER_INIT
static

Animation player driving the hero metasprite.

◆ hero_style

const MetaspriteStyle hero_style = { .baseTile = 0, .size = OBJ_SMALL }
static

Metasprite pointer table generated by opensnes-sprite sheet (res/hero.png.toml).

Defines hero_metasprite0..7 (each a MetaspriteItem[] terminated by METASPR_TERM) plus hero_metasprites[8], the pointer table the animation clips index. One entry per cell of the hero.png sheet, in sheet order.

Animation clips generated by opensnes-sprite anim from res/hero.json.

Defines hero_walk / hero_wave (AnimClip), the hero_anims[] pointer table and the HERO_ANIM_* index enum. Frame values index hero_metasprites[] above.

The hero's sheet starts at tile 0 and its pieces are the small OBJ size; the frame comes from the animation at each call.