Very basic animations
This commit is contained in:
17
game/systems/animations.c
Normal file
17
game/systems/animations.c
Normal file
@@ -0,0 +1,17 @@
|
||||
#include "systems.h"
|
||||
|
||||
void updateAnimations(ecs_iter_t *it) {
|
||||
Animation *anim = ecs_field(it, Animation, 1);
|
||||
TextureRegion *t = ecs_field(it, TextureRegion, 2);
|
||||
|
||||
float dt = GetFrameTime();
|
||||
|
||||
for (i32 i = 0; i < it->count; i++) {
|
||||
anim[i].elapsed += dt;
|
||||
if (anim[i].elapsed < anim[i].frameDuration) continue;
|
||||
|
||||
anim[i].currFrame = (anim[i].currFrame + 1) % anim[i].frameCount;
|
||||
anim[i].elapsed = 0.0f;
|
||||
t[i].rec.x = anim[i].firstFrame.rec.x + anim[i].currFrame * t[i].rec.width;
|
||||
}
|
||||
}
|
||||
@@ -6,5 +6,6 @@
|
||||
#include "../components.h"
|
||||
|
||||
void renderEntities(ecs_iter_t *it);
|
||||
void updateAnimations(ecs_iter_t *it);
|
||||
|
||||
#endif //PIXELDEFENSE_SYSTEMS_H
|
||||
|
||||
Reference in New Issue
Block a user