A simple animation system capable of loading a spritesheet with fixed sized frames.
More...
|
| Animation * | Animation_Create (AnimationData *data) |
| | Creates a new animation from animation data.
|
| |
| void | Animation_Destroy (Animation *animation) |
| | Destroys an animation and frees its memory.
|
| |
| int | Animation_AddClipFromGrid (Animation *animation, const char *name, int startFrameIndex, int endFrameIndex, float frameDuration, bool looping) |
| | Adds a new animation clip from a grid-based spritesheet.
|
| |
| void | Animation_Play (Animation *animation, const char *clipName) |
| | Plays an animation clip by name.
|
| |
| void | Animation_Stop (Animation *animation) |
| | Stops the animation.
|
| |
| void | Animation_Pause (Animation *animation) |
| | Pauses the animation.
|
| |
| void | Animation_Resume (Animation *animation) |
| | Resumes the animation.
|
| |
| void | Animation_Update (Animation *animation) |
| | Updates the animation.
|
| |
| void | Animation_Render (Animation *animation, Vec2 destPosition, Vec2 destSize, float angle, SDL_Point *rotationCenter, SDL_RendererFlip flip) |
| | Renders the animation.
|
| |
| bool | Animation_ClipIsFinished (Animation *animation) |
| |
A simple animation system capable of loading a spritesheet with fixed sized frames.
The spritesheet you select should have all of its states on it, like running, walking etc.
- Warning
- This system doesn't support loading animation clips from multiple files into one animation.
Usage
To load an animation, you need 3 steps:
Step 1: Create animation with an AnimationData struct
An example of an AnimationData struct can be found in src/Game/Player/player_data.c
After that, you can call:
Animation * Animation_Create(AnimationData *animData)
Creates a new animation from animation data.
Definition animation.c:30
The main animation structure.
Definition animation.h:83
Step 2: Play the animation based on a certain state
void Animation_Play(Animation *animation, const char *clipName)
Plays an animation clip by name.
Definition animation.c:221
Step 3: Update and render the animation every frame
animation,
angle,
NULL,
SDL_FLIP_NONE
);
void Animation_Update(Animation *animation)
Updates the current animation frame.
Definition animation.c:75
void Animation_Render(Animation *animation, Vec2 destPosition, Vec2 destSize, float angle, SDL_Point *rotationCenter, SDL_RendererFlip flip)
Renders the current frame of an animation.
Definition animation.c:276
A 2D vector structure.
Definition vec2.h:81
- Author
- Mango
- Date
- 2025-03-01
| int Animation_AddClipFromGrid |
( |
Animation * |
animation, |
|
|
const char * |
name, |
|
|
int |
startFrameIndex, |
|
|
int |
endFrameIndex, |
|
|
float |
frameDuration, |
|
|
bool |
looping |
|
) |
| |
Adds a new animation clip from a grid-based spritesheet.
- Parameters
-
| animation | The animation to add the clip to. |
| name | The name of the clip. |
| startFrameIndex | The index of the first frame. |
| endFrameIndex | The index of the last frame. |
| frameDuration | The duration of each frame in seconds. |
| looping | Whether the animation should loop. |
- Returns
- The index of the newly added clip.
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.
- Parameters
-
| 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 |
- Returns
- int 0 on success, 1 on failure