-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimationController.hpp
More file actions
50 lines (39 loc) · 1.3 KB
/
AnimationController.hpp
File metadata and controls
50 lines (39 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#pragma once
#include "Animation.hpp"
#include "Enums.hpp"
#include <unordered_map>
#include <map>
template<typename StateEnum>
class AnimationController
{
public:
void addStateAnimation(StateEnum state, DirectionEnum direction, Animation animation) {
animations[state][direction] = animation;
}
void update(float delta, StateEnum state, DirectionEnum direction) {
// change state if needed
if (state != currentState) {
animations[currentState][currentDirection].stop();
animations[currentState][currentDirection].reset();
currentState = state;
animations[currentState][currentDirection].play();
}
// Change direction if needed
if (direction != currentDirection) {
if (direction == DirectionEnum::NONE) {
animations[currentState][currentDirection].stop();
return;
}
animations[currentState][currentDirection].stop();
animations[currentState][currentDirection].reset();
currentDirection = direction;
animations[currentState][currentDirection].play();
}
animations[currentState][currentDirection].updateAnimation(delta);
}
private:
std::unordered_map<StateEnum, std::unordered_map<DirectionEnum, Animation>> animations;
//std::unordered_map<DirectionEnum, Animation> animations;
DirectionEnum currentDirection = DirectionEnum::NONE;
StateEnum currentState;
};