R-Type
R-Type project
Animation.hpp
1 /*
2 ** EPITECH PROJECT, 2022
3 ** gameEngine2
4 ** File description:
5 ** Animation
6 */
7 
8 #ifndef ANIMATION_HPP_
9 #define ANIMATION_HPP_
10 
11 #include <functional>
12 
13 #include "KapEngine.hpp"
14 #include "KapEngineEvents.hpp"
15 
16 namespace KapEngine {
17 
25  class Animation : public Component {
26  public:
27 
28  Animation(std::shared_ptr<GameObject> go);
29  ~Animation();
30 
31  void onFixedUpdate() override;
32 
39  bool isEnded() {
40  PROFILER_FUNC_START();
41  PROFILER_FUNC_END();
42  return _end;
43  }
44 
51  void loop(bool b) {
52  PROFILER_FUNC_START();
53  _loop = b;
54  PROFILER_FUNC_END();
55  }
56 
63  void play(bool b) {
64  PROFILER_FUNC_START();
65  _startAnim = b;
66  if (b) {
67  _end = false;
68  _currTime = 0;
69  onPlay();
70  }
71  PROFILER_FUNC_END();
72  }
73 
79  void setTiming(int64_t const& time) {
80  PROFILER_FUNC_START();
81  _timing = time;
82  PROFILER_FUNC_END();
83  }
84 
90  void setTiming(Time::ETime const& time) {
91  PROFILER_FUNC_START();
92  _timing = time;
93  PROFILER_FUNC_END();
94  }
95 
96  virtual void onPlay() {}
97  virtual void onUpdateAnim();
98  virtual void onResetAnim();
99 
100  virtual Animation &operator=(Animation const& anim) {
101  PROFILER_FUNC_START();
102  _startAnim = anim._startAnim;
103  _loop = anim._loop;
104  _end = anim._end;
105  _timing = anim._timing;
106  _currTime = anim._currTime;
107  PROFILER_FUNC_END();
108 
109  return *this;
110  }
111 
112  Events::EventAction &getOnEnd() {
113  PROFILER_FUNC_START();
114  PROFILER_FUNC_END();
115  return _onEnd;
116  }
117 
118  Events::EventAction &getOnStart() {
119  PROFILER_FUNC_START();
120  PROFILER_FUNC_END();
121  return _onStart;
122  }
123 
124  Events::EventAction &getOnRestart() {
125  PROFILER_FUNC_START();
126  PROFILER_FUNC_END();
127  return _onRestart;
128  }
129 
130  protected:
131 
132  bool _startAnim = false;
133  bool _loop = false;
134  bool _end = false;
135  Time::ETime _timing;
136  int64_t _currTime = 0;
137 
138  Events::EventAction _onEnd;
139  Events::EventAction _onRestart;
140  Events::EventAction _onStart;
141  private:
142  bool _reseted = false;
143  };
144 
145 }
146 
147 #endif /* !ANIMATION_HPP_ */
KapEngine::Animation::setTiming
void setTiming(int64_t const &time)
Set the animation duration.
Definition: Animation.hpp:79
KapEngine::Time::ETime
Engine Time is internal time system of engine.
Definition: ETime.hpp:25
KapEngine::Animation::setTiming
void setTiming(Time::ETime const &time)
Set the animation duration.
Definition: Animation.hpp:90
KapEngine::Animation::play
void play(bool b)
Definition: Animation.hpp:63
KapEngine::Animation::loop
void loop(bool b)
Definition: Animation.hpp:51
KapEngine::Component
Definition: Component.hpp:38
KapEngine::Animation::isEnded
bool isEnded()
is animation ended
Definition: Animation.hpp:39
KapEngine::Animation
Definition: Animation.hpp:25
KapEngine::Animation::onFixedUpdate
void onFixedUpdate() override
call eachv x ms
Definition: Animation.cpp:14
KapEngine
main namespace
Definition: Component.hpp:17