#include <spriteanimation.h>
Collaboration diagram for SpriteAnimation:
Public Types | |
show_first_frame | |
show_last_frame | |
show_blank | |
enum | SpriteShowOnFinish { show_first_frame, show_last_frame, show_blank } |
Public Member Functions | |
SpriteAnimation (Sprite &sprite) | |
SpriteAnimation (const SpriteAnimation &other, Sprite &sprite) | |
void | Start () |
void | Update () |
void | Finish () |
bool | IsFinished () const |
void | SetSpeedFactor (float nv_speed) |
void | SetPlayBackward (bool enable) |
void | SetLoopMode (bool enable) |
void | SetPingPongMode (bool enable) |
void | SetShowOnFinish (SpriteShowOnFinish show) |
SpriteShowOnFinish | GetShowOnFinish () const |
Private Attributes | |
Sprite & | sprite |
unsigned int | last_update |
float | speed_factor |
int | frame_delta |
bool | finished |
SpriteShowOnFinish | show_on_finish |
bool | loop |
bool | pingpong |
Definition at line 32 of file spriteanimation.h.
Definition at line 35 of file spriteanimation.h.
00035 { 00036 show_first_frame, 00037 show_last_frame, 00038 show_blank 00039 } SpriteShowOnFinish;
SpriteAnimation::SpriteAnimation | ( | Sprite & | sprite | ) |
Definition at line 29 of file spriteanimation.cpp.
00029 : 00030 sprite(p_sprite) 00031 { 00032 last_update = Time::GetInstance()->Read(); 00033 speed_factor = 1.0f; 00034 frame_delta = 1; 00035 finished = false; 00036 show_on_finish = show_last_frame; 00037 loop = true; 00038 pingpong = false; 00039 }
Here is the call graph for this function:
SpriteAnimation::SpriteAnimation | ( | const SpriteAnimation & | other, | |
Sprite & | sprite | |||
) |
Definition at line 41 of file spriteanimation.cpp.
00041 : 00042 sprite(p_sprite) 00043 { 00044 last_update = other.last_update; 00045 speed_factor = other.speed_factor; 00046 frame_delta = other.frame_delta; 00047 finished = other.finished; 00048 show_on_finish = other.show_on_finish; 00049 loop = other.loop; 00050 pingpong = other.pingpong; 00051 }
void SpriteAnimation::Finish | ( | ) |
Definition at line 69 of file spriteanimation.cpp.
00069 { 00070 finished = true; 00071 }
Here is the caller graph for this function:
SpriteAnimation::SpriteShowOnFinish SpriteAnimation::GetShowOnFinish | ( | ) | const |
Definition at line 141 of file spriteanimation.cpp.
00141 { 00142 return show_on_finish; 00143 }
Here is the caller graph for this function:
bool SpriteAnimation::IsFinished | ( | ) | const |
Definition at line 129 of file spriteanimation.cpp.
00129 { 00130 return finished; 00131 }
Here is the caller graph for this function:
void SpriteAnimation::SetLoopMode | ( | bool | enable | ) |
Definition at line 133 of file spriteanimation.cpp.
00133 { 00134 loop = enable; 00135 }
Here is the caller graph for this function:
void SpriteAnimation::SetPingPongMode | ( | bool | enable | ) |
Definition at line 137 of file spriteanimation.cpp.
00137 { 00138 pingpong = enable; 00139 }
Here is the caller graph for this function:
void SpriteAnimation::SetPlayBackward | ( | bool | enable | ) |
Definition at line 62 of file spriteanimation.cpp.
00062 { 00063 if (enable) 00064 frame_delta = -1; 00065 else 00066 frame_delta = 1; 00067 }
Here is the caller graph for this function:
void SpriteAnimation::SetShowOnFinish | ( | SpriteShowOnFinish | show | ) |
Definition at line 124 of file spriteanimation.cpp.
00124 { 00125 show_on_finish = show; 00126 loop = false; 00127 }
Here is the caller graph for this function:
void SpriteAnimation::SetSpeedFactor | ( | float | nv_speed | ) |
void SpriteAnimation::Start | ( | ) |
Definition at line 57 of file spriteanimation.cpp.
00057 { 00058 finished = false; 00059 last_update = Time::GetInstance()->Read(); 00060 }
Here is the call graph for this function:
Here is the caller graph for this function:
void SpriteAnimation::Update | ( | ) |
Definition at line 73 of file spriteanimation.cpp.
00073 { 00074 if (finished) return; 00075 00076 Time * global_time = Time::GetInstance(); 00077 if (global_time->Read() < (last_update + sprite.GetCurrentFrameObject().delay)) 00078 return; 00079 const unsigned int current_frame = sprite.GetCurrentFrame(); 00080 const unsigned int frame_count = sprite.GetFrameCount(); 00081 00082 //Delta to next frame used to enable frameskip 00083 //if delay between 2 frame is < fps 00084 int delta_to_next_f = (int)((float)((global_time->Read() - last_update) / sprite.GetCurrentFrameObject().delay) * speed_factor); 00085 last_update += (int)((float)(delta_to_next_f * sprite.GetCurrentFrameObject().delay) / speed_factor); 00086 00087 //Animation is finished, when last frame have been fully played 00088 bool finish; 00089 if (frame_delta < 0) 00090 finish = ((int)current_frame + frame_delta * delta_to_next_f) <= -1; 00091 else 00092 finish = frame_count <= (current_frame + frame_delta * delta_to_next_f); 00093 00094 if (finish && !loop && (!pingpong || frame_delta < 0)) 00095 Finish(); 00096 else 00097 { 00098 unsigned int next_frame = ( current_frame + frame_delta * delta_to_next_f ) % frame_count; 00099 00100 if(pingpong) 00101 { 00102 if( frame_delta>0 && ( current_frame + frame_delta * delta_to_next_f ) >= frame_count) 00103 { 00104 next_frame = frame_count - next_frame -2; 00105 frame_delta = - frame_delta; 00106 } 00107 else 00108 if( frame_delta<0 && ( (int)current_frame + frame_delta * delta_to_next_f ) <= -1) 00109 { 00110 next_frame = (-((int)current_frame + frame_delta * delta_to_next_f )) % frame_count; 00111 frame_delta = - frame_delta; 00112 } 00113 } 00114 00115 if(next_frame != current_frame) 00116 { 00117 if(next_frame >= frame_count) 00118 next_frame = 0; 00119 sprite.SetCurrentFrame(next_frame); 00120 } 00121 } 00122 }
Here is the call graph for this function:
Here is the caller graph for this function:
bool SpriteAnimation::finished [private] |
Definition at line 50 of file spriteanimation.h.
int SpriteAnimation::frame_delta [private] |
Definition at line 47 of file spriteanimation.h.
unsigned int SpriteAnimation::last_update [private] |
Definition at line 45 of file spriteanimation.h.
bool SpriteAnimation::loop [private] |
Definition at line 54 of file spriteanimation.h.
bool SpriteAnimation::pingpong [private] |
Definition at line 55 of file spriteanimation.h.
Definition at line 51 of file spriteanimation.h.
float SpriteAnimation::speed_factor [private] |
Definition at line 46 of file spriteanimation.h.
Sprite& SpriteAnimation::sprite [private] |
Definition at line 42 of file spriteanimation.h.