|
|
|
@ -128,6 +128,25 @@ namespace olc::utils::Animate2D |
|
|
|
|
return m_vFrames[ConvertTimeToFrame(fTime)]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Returns the current frame of animation as a frame index.
|
|
|
|
|
inline const size_t GetFrameIndex(const float fTime) const |
|
|
|
|
{ |
|
|
|
|
return ConvertTimeToFrame(fTime); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Returns how long a cycle of a full animation takes in seconds.
|
|
|
|
|
inline const float GetTotalAnimationDuration()const{ |
|
|
|
|
switch (m_nStyle) |
|
|
|
|
{ |
|
|
|
|
case Style::Repeat: |
|
|
|
|
case Style::OneShot: |
|
|
|
|
return m_vFrames.size()*m_fFrameDuration; |
|
|
|
|
case Style::PingPong: |
|
|
|
|
case Style::Reverse: //These two require twice as much time (minus one frame) to complete a full animation cycle.
|
|
|
|
|
return m_vFrames.size()*m_fFrameDuration*2.f-m_fFrameDuration; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
|
|
|
|
|
inline const size_t ConvertTimeToFrame(const float fTime) const |
|
|
|
@ -171,15 +190,18 @@ namespace olc::utils::Animate2D |
|
|
|
|
public: |
|
|
|
|
Animation() = default; |
|
|
|
|
float mult = 1.f; |
|
|
|
|
StatesEnum currentStateName; |
|
|
|
|
|
|
|
|
|
inline bool ChangeState(AnimationState& state, const StatesEnum& sStateName, const float frameMult) |
|
|
|
|
{ |
|
|
|
|
mult=frameMult; |
|
|
|
|
currentStateName=sStateName; |
|
|
|
|
return ChangeState(state,sStateName); |
|
|
|
|
} |
|
|
|
|
// Change an animation state token to a new state
|
|
|
|
|
inline bool ChangeState(AnimationState& state, const StatesEnum& sStateName) const |
|
|
|
|
{ |
|
|
|
|
currentStateName=sStateName; |
|
|
|
|
size_t idx = m_mapStateIndices.at(sStateName); |
|
|
|
|
if (state.nIndex != idx) |
|
|
|
|
{ |
|
|
|
@ -204,6 +226,10 @@ namespace olc::utils::Animate2D |
|
|
|
|
return m_vSequences[state.nIndex].GetFrame(state.fTime); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
inline const size_t GetFrameIndex()const{ |
|
|
|
|
return m_vSequences[state.nIndex].GetFrameIndex(state.fTime); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public: |
|
|
|
|
// Add a named Frame sequence as a state
|
|
|
|
|
inline void AddState(const StatesEnum& sStateName, const FrameSequence& sequence) |
|
|
|
|