animation is now decoupled from sprite

This commit is contained in:
huaqo-games
2025-02-08 17:47:12 +01:00
parent 0c73d94187
commit bcb1577694
7 changed files with 121 additions and 4 deletions
+28
View File
@@ -0,0 +1,28 @@
#ifndef ANIMSPRITE_H
#define ANIMSPRITE_H
typedef struct {
int currentFrame;
int maxFrame;
int framesCounter;
int framesSpeed;
float animTimer;
} Animation;
void UpdateAnimation(Animation *animation, float deltaTime) {
animation->animTimer += deltaTime;
float frameTime = 1.0f / animation->framesSpeed;
if (animation->animTimer < frameTime) {
return;
}
animation->animTimer -= frameTime;
animation->currentFrame++;
if (animation->currentFrame >= animation->maxFrame) {
animation->currentFrame = 0;
}
}
#endif // ANIMSPRITE_H