Sprite animation system implementation. More...
#include <animation.h>#include <stdlib.h>#include <string.h>#include <app.h>#include <time_system.h>Functions | |
| Animation * | Animation_Create (AnimationData *animData) |
| Creates a new animation from animation data. | |
| void | Animation_Update (Animation *animation) |
| Updates the current animation frame. | |
| void | Animation_Destroy (Animation *animation) |
| Destroys an animation and frees its resources. | |
| int | Animation_AddClipFromGrid (Animation *animation, const char *name, int startFrameIndex, int endFrameIndex, float frameDuration, bool looping) |
| Adds an animation clip from a spritesheet grid. | |
| void | Animation_Play (Animation *animation, const char *clipName) |
| Plays an animation clip by name. | |
| void | Animation_Stop (Animation *animation) |
| Stops the current animation and resets it. | |
| void | Animation_Pause (Animation *animation) |
| Pauses the current animation. | |
| void | Animation_Resume (Animation *animation) |
| Resumes a paused animation. | |
| void | Animation_Render (Animation *animation, Vec2 destPosition, Vec2 destSize, float angle, SDL_Point *rotationCenter, SDL_RendererFlip flip) |
| Renders the current frame of an animation. | |
| bool | Animation_ClipIsFinished (Animation *animation) |
Sprite animation system implementation.
Implements a flexible animation system that supports spritesheet-based animations with multiple clips, variable frame rates, and playback controls.
| int Animation_AddClipFromGrid | ( | Animation * | animation, |
| const char * | name, | ||
| int | startFrameIndex, | ||
| int | endFrameIndex, | ||
| float | frameDuration, | ||
| bool | looping | ||
| ) |
Adds an animation clip from a spritesheet grid.
Adds a new animation clip from a grid-based spritesheet.
Creates a new clip by extracting frames from the spritesheet using a grid-based layout. Frame indices start from 0, reading from left to right, then top to bottom.
| animation | The animation to add the clip to |
| name | Name of the clip (e.g., "idle", "walk") |
| startFrameIndex | Index of the first frame in the clip |
| endFrameIndex | Index of the last frame in the clip |
| frameDuration | Time between frames in seconds |
| looping | Whether the animation should loop |
| bool Animation_ClipIsFinished | ( | Animation * | animation | ) |
| Animation * Animation_Create | ( | AnimationData * | animData | ) |
Creates a new animation from animation data.
This only works with spritesheets with constant frame size. After creating an animation, calling Animation_AddClipFromGrid can add additional animation clips.
| animData | Pointer to the animation data configuration |
| void Animation_Destroy | ( | Animation * | animation | ) |
Destroys an animation and frees its resources.
Destroys an animation and frees its memory.
| animation | Pointer to the animation to destroy |
| void Animation_Pause | ( | Animation * | animation | ) |
Pauses the current animation.
Pauses the animation.
| animation | The animation to pause |
| void Animation_Play | ( | Animation * | animation, |
| const char * | clipName | ||
| ) |
Plays an animation clip by name.
If the target clip is already playing, this function does nothing.
| animation | The animation to play |
| clipName | The name of the clip to play |
| void Animation_Render | ( | Animation * | animation, |
| Vec2 | destPosition, | ||
| Vec2 | destSize, | ||
| float | angle, | ||
| SDL_Point * | rotationCenter, | ||
| SDL_RendererFlip | flip | ||
| ) |
Renders the current frame of an animation.
Renders the animation.
| animation | The animation to render |
| destPosition | Position where the animation should be drawn |
| destSize | Size of the drawn animation |
| angle | Rotation angle in degrees |
| rotationCenter | Center point for rotation |
| flip | Flip flags for rendering (horizontal/vertical) |
| void Animation_Resume | ( | Animation * | animation | ) |
Resumes a paused animation.
Resumes the animation.
| animation | The animation to resume |
| void Animation_Stop | ( | Animation * | animation | ) |
Stops the current animation and resets it.
Stops the animation.
| animation | The animation to stop |
| void Animation_Update | ( | Animation * | animation | ) |
Updates the current animation frame.
Updates the animation.
This function should be called every frame to advance animations. It handles transitions between frames, respecting frame durations and looping settings.
| animation | Pointer to the animation to update |