Animator
The Animator component drives a SpriteRenderer by cycling through an Animation's Sprite frames automatically. Attach it to a SpriteRenderer and it handles frame advancement every tick.
Setup
The animation pipeline now separates generated raw animation assets from per-instance playback parameters. GIFs are converted into WE_AnimationRaw assets (see documentation/asset_pipeline.md). At runtime you wrap a raw asset with playback settings into a WE_Animation and pass that to the Animator.
Example:
// Generated by the asset pipeline:
// extern const WE_AnimationRaw PLAYER_WALK;
// In game code â wrap the raw asset with playback params:
constexpr WE_Animation WALK = { &Assets::PLAYER_WALK, 8, true };
class Player : public GameObject {
public:
SpriteRenderer spriteRenderer = SpriteRenderer(this, &Assets::PLAYER, RenderLayer::Player);
Animator animator = Animator(&spriteRenderer, &WALK);
};
The engine ticks the animator automatically every frame. Pixel arrays and Sprite objects remain constexpr (flash-resident); WE_Animation is a small, constexpr wrapper that holds the raw asset pointer and playback params.
Constructor
Animator(SpriteRenderer* mySpriteRenderer,
const WE_Animation* animation);
| Parameter | Description |
|---|---|
mySpriteRenderer |
The SpriteRenderer this animator controls |
animation |
The WE_Animation wrapper to play (contains raw, frameDuration, looping) |
Controls
Switching Animations
Swap the active animation at runtime â for example switching from walk to jump:
animator.setAnimation(JUMP);
This resets the frame counter and starts the new animation from the beginning.
Jumping to a Frame
Jump to a specific frame immediately â resets the tick counter:
animator.setFrame(0); // go back to first frame
Playback Speed
Change how many ticks each frame is shown for:
animator.setFrameDuration(4); // faster
animator.setFrameDuration(16); // slower
Pause and Resume
animator.pause();
animator.resume();
Getters
animator.getCurrentFrame(); // returns current frame index
animator.isPaused(); // returns true if paused
Frame Duration and Speed
frameDuration is measured in engine ticks, not milliseconds. At 30fps:
| frameDuration | Frames per second |
|---|---|
| 2 | 15 fps |
| 4 | 7.5 fps |
| 8 | 3.75 fps |
| 15 | 2 fps |
Adjust based on how snappy you want the animation to feel.
Memory
All pixel data, Sprite arrays, and Animation objects should be declared constexpr so they live in flash. The Animator itself only stores pointers and counters â a few bytes of RAM regardless of frame count.