HatchitGame
ht_tween_component.h
1 
15 #pragma once
16 
17 #include <ht_component.h>
18 #include <ht_tween_value.h>
19 #include <stdint.h>
20 #include <vector>
21 
22 namespace Hatchit {
23 
24  namespace Game {
25 
29  enum class TweenPlayMode : uint8_t
30  {
31  Once,
32  Loop,
33  PingPong
34  };
35 
39  enum class TweenMethod : uint8_t
40  {
41  Linear,
42  QuadraticEaseOut,
43  QuadraticEaseIn,
44  QuadraticEaseInOut,
45  QuadraticEaseOutIn,
46  ExponentialEaseOut,
47  ExponentialEaseIn,
48  ExponentialEaseInOut,
49  ExponentialEaseOutIn,
50  CubicEaseOut,
51  CubicEaseIn,
52  CubicEaseInOut,
53  CubicEaseOutIn,
54  QuarticEaseOut,
55  QuarticEaseIn,
56  QuarticEaseInOut,
57  QuarticEaseOutIn,
58  QuinticEaseOut,
59  QuinticEaseIn,
60  QuinticEaseInOut,
61  QuinticEaseOutIn,
62  CircularEaseOut,
63  CircularEaseIn,
64  CircularEaseInOut,
65  CircularEaseOutIn,
66  SineEaseOut,
67  SineEaseIn,
68  SineEaseInOut,
69  SineEaseOutIn,
70  ElasticEaseOut,
71  ElasticEaseIn,
72  ElasticEaseInOut,
73  ElasticEaseOutIn,
74  /*
75  BounceEaseOut,
76  BounceEaseIn,
77  BounceEaseInOut,
78  BounceEaseOutIn,
79  */
80  BackEaseOut,
81  BackEaseIn,
82  BackEaseInOut,
83  BackEaseOutIn,
84 
85  TweenMethodCount
86  };
87 
91  class HT_API TweenComponent : public Component
92  {
93  public:
103  typedef float(*TweenFunction)(float start, float end, float time, float duration);
104 
108  TweenComponent();
109 
113  virtual ~TweenComponent();
114 
115  virtual Core::JSON VSerialize(void) override;
116  virtual bool VDeserialize(const Core::JSON& jsonObject) override;
117 
121  float GetDuration() const;
122 
126  TweenMethod GetMethod() const;
127 
131  TweenPlayMode GetPlayMode() const;
132 
136  bool IsPlaying() const;
137 
143  bool Play();
144 
151  bool Play(float duration);
152 
160  bool Play(float duration, TweenMethod method);
161 
170  bool Play(float duration, TweenMethod method, TweenPlayMode mode);
171 
177  void SetDuration(float duration);
178 
184  void SetMethod(TweenMethod method);
185 
191  void SetPlayMode(TweenPlayMode mode);
192 
196  void Stop();
197 
201  void VOnInit() override;
202 
208  virtual void VOnUpdate() override;
209 
216  void VOnDestroy() override;
217 
221  Component* VClone(void) const override;
222 
223  virtual Core::Guid VGetComponentId(void) const override;
224  protected:
225  static std::vector<TweenFunction> s_tweenFunctions;
226 
227  TweenValue m_targetValue;
228  TweenValue m_startValue;
229  TweenValue m_endValue;
230  TweenFunction m_tweenFunction;
231  TweenMethod m_tweenMethod;
232  TweenPlayMode m_tweenPlayMode;
233  float m_startTime;
234  float m_duration;
235  bool m_isPlaying;
236 
240  static void CreateTweenFunctions();
241 
245  bool AreValuesCompatible() const;
246 
252  void VOnEnabled() override;
253 
260  void VOnDisabled() override;
261 
262  private:
268  bool BeginPlay();
269 
275  void OnStop(bool interrupted);
276  };
277 
278  }
279 
280 }
Definition: ht_component.h:42
Hatchit Engine Copyright(c) 2015-2016 Third-Degree.
Definition: ht_glfwkeyboard.h:21
Defines the base for tween-based components.
Definition: ht_tween_component.h:91
Defines a tween value.
Definition: ht_tween_value.h:38