learn-dlang/lesson#29 - Player spritesh.../ourGame/source/game/animation/manager.d

31 lines
689 B
D

module game.animation.manager;
import raylib;
import game.animation.animation;
struct AnimationManager {
private Animation[KeyboardKey] animations;
private KeyboardKey lastKey;
void add(in KeyboardKey key, Animation animation) {
animations[key] = animation;
lastKey = key;
}
void update(in KeyboardKey key) {
if (key in animations) {
animations[key].start();
animations[key].update();
lastKey = key;
} else {
animations[lastKey].stop();
animations[lastKey].reset();
}
}
void draw(in Vector2 position) {
animations[lastKey].draw(position);
}
}