Direction-based sprite animation with horizontal flip. More...
#include <snes.h>Classes | |
| struct | Monster |
| Sprite state structure holding position, animation, and direction. More... | |
Macros | |
| #define | ANIM_DELAY 6 |
| Number of frames to hold each animation frame before advancing. | |
| #define | FRAMES_PER_ANIMATION 3 |
| Number of distinct frames in each directional walk cycle. | |
Enumerations | |
| enum | { SCREEN_TOP = -16 , SCREEN_BOTTOM = 224 , SCREEN_LEFT = -16 , SCREEN_RIGHT = 256 } |
| Screen edge boundaries for sprite clamping. More... | |
| enum | SpriteState { W_DOWN = 0 , W_UP = 1 , W_RIGHT = 2 , W_LEFT = 2 } |
| Animation direction states. More... | |
Functions | |
| int | main (void) |
| Entry point: animated character sprite with D-PAD movement. | |
Variables | |
| Monster | monster = {100, 100, 0, 0, 0, W_DOWN, 0} |
| The player-controlled character sprite, initialized facing down at (100, 100) | |
| u8 | sprite_pal [] |
| Palette for the character sprite (16 colors, 4bpp) | |
| u8 | sprite_pal_end [] |
| u8 | sprite_tiles [] |
| Sprite sheet tile data containing all animation frames (defined in data.asm) | |
| u8 | sprite_tiles_end [] |
Direction-based sprite animation with horizontal flip.
Demonstrates a classic sprite animation pattern: a character sprite with multiple directional walk cycles (down, up, left, right). Each direction uses a different row of frames in the sprite sheet, and the left-facing animation reuses the right-facing frames with the OAM horizontal flip bit (bit 6 of attribute byte).
Animation is frame-paced with a configurable delay between tile changes. The sprite's OAM tile number is updated each frame via oamSet() to point at the correct frame in the pre-loaded sprite sheet. Movement is controlled with the D-PAD and clamped to screen boundaries.
Ported from PVSnesLib AnimatedSprite example.
| #define ANIM_DELAY 6 |
Number of frames to hold each animation frame before advancing.
At 60fps, a delay of 6 means each walk frame lasts 6/60 = 100ms, producing a 300ms walk cycle (3 frames x 100ms). Adjust this value to make the animation faster (lower) or slower (higher).
| #define FRAMES_PER_ANIMATION 3 |
Number of distinct frames in each directional walk cycle.
| anonymous enum |
Screen edge boundaries for sprite clamping.
Negative values allow the sprite to partially leave the screen (16px margin), which looks more natural than stopping exactly at the visible edge.
| enum SpriteState |
Animation direction states.
Each state maps to a row in the sprite sheet. W_LEFT reuses the W_RIGHT row and sets the OAM horizontal flip bit to mirror the frames, which is a common SNES technique to halve the sprite sheet size for left/right symmetric characters.
| Enumerator | |
|---|---|
| W_DOWN | Walking downward (facing camera) |
| W_UP | Walking upward (facing away) |
| W_RIGHT | Walking right |
| W_LEFT | Walking left — reuses W_RIGHT tiles with horizontal flip |
| int main | ( | void | ) |
Entry point: animated character sprite with D-PAD movement.
Loads a multi-frame sprite sheet, initializes OAM, and runs a game loop that reads D-PAD input, updates the sprite position and animation state, then writes the new tile number and flip flags to OAM each frame.
Current joypad state — bits set for each held button
The player-controlled character sprite, initialized facing down at (100, 100)
|
extern |
Palette for the character sprite (16 colors, 4bpp)
| u8 sprite_pal_end[] |
|
extern |
Sprite sheet tile data containing all animation frames (defined in data.asm)
| u8 sprite_tiles_end[] |