-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnimationHolder.h
85 lines (63 loc) · 1.47 KB
/
AnimationHolder.h
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#ifndef ANIMATION_H
#define ANIMATION_H
#include <vector>
#include <map>
#include <string>
#include <SFML/Graphics/Texture.hpp>
#include <SFML/Graphics/Sprite.hpp>
#include <SFML/Graphics/Rect.hpp>
namespace sf
{
class RenderTarget;
}
class Animation
{
public:
Animation() = default;
Animation(sf::Texture& texture, int x, int y, int width, int height, int count, float speed, int step);
sf::Sprite& GetSprite() { return sprite; }
void Tick(float time);
void SetFlip(bool flip) { bFlip = flip; }
void Play() { bPlaying = true; }
void Pause() { bPlaying = false; }
private:
std::vector<sf::IntRect> frames;
std::vector<sf::IntRect> frames_flip;
sf::Sprite sprite;
float currentFrame = 0.f;
float speed = 0.f;
bool bFlip = false;
bool bPlaying = true;
bool bLoop = true;
};
class AnimationHolder
{
public:
void Create(const std::string& name, sf::Texture& texture, int x, int y, int width, int height, int count,
float speed, int step);
void Draw(sf::RenderTarget& renderTarget, int x, int y);
void Set(const std::string& name)
{
currentAnimationName = name;
}
void Flip(bool bFlip = true)
{
animations[currentAnimationName].SetFlip(bFlip);
}
void Tick(float time)
{
animations[currentAnimationName].Tick(time);
}
void Play()
{
animations[currentAnimationName].Play();
}
void Pause()
{
animations[currentAnimationName].Pause();
}
private:
std::string currentAnimationName;
std::map<std::string, Animation> animations;
};
#endif