GameKit  0.0.1a
C++ gamedev tools
SpriteAnimation.cpp
Go to the documentation of this file.
1 /*
2  * =====================================================================================
3  *
4  * Filename: SpriteAnimation.cpp
5  *
6  * Description:
7  *
8  * Created: 25/01/2018 04:07:30
9  *
10  * Author: Quentin Bazin, <quent42340@gmail.com>
11  *
12  * =====================================================================================
13  */
15 
16 namespace gk {
17 
18 void SpriteAnimation::reset(u16 frameID) {
19  m_timer.reset();
20  m_timer.setTime(frameID * m_delay);
21 }
22 
24  m_timer.start();
25 
26  // if(!Sprite::pause) m_isPaused = false;
27 }
28 
30  m_timer.stop();
31 
32  // if(!Sprite::pause) m_isPaused = true;
33 }
34 
36  if(/* Sprite::pause || */m_isPaused) {
37  stop();
38  } else {
39  start();
40  }
41 
42  if(isFinished()) {
43  if(m_isRepeated) {
44  reset();
45  start();
46  } else {
47  stop();
48  }
49  }
50 }
51 
53  return m_frames[frameID];
54 }
55 
57  u16 frameID = displayedFramesAmount();
58  if(frameID >= m_frames.size()) {
59  return getFrame(m_frames.size() - 1);
60  } else {
61  return getFrame(frameID);
62  }
63 }
64 
66  if (m_delay == 0)
67  return 0;
68 
69  return m_timer.time() / m_delay;
70 }
71 
72 }
73 
void start()
Start the timer.
Definition: Timer.cpp:31
void setTime(u32 time)
Set time.
Definition: Timer.cpp:52
void stop()
Stop the timer.
Definition: Timer.cpp:24
unsigned short u16
Definition: IntTypes.hpp:22
std::vector< u16 > m_frames
void reset(u16 frameID=0)
void reset()
Reset the timer.
Definition: Timer.cpp:38
u16 getFrame(u16 frameID) const
u32 time() const
Get time.
Definition: Timer.cpp:44
u16 displayedFramesAmount() const