Files
dae16-VerhulstBram-GameProject/Game/Animations/Animation.h
Bram Verhulst d3b932df22 Fix digging
2024-05-07 10:35:18 +02:00

48 lines
929 B
C++

#pragma once
#include "Texture.h"
class Animation
{
public:
Animation(Texture* pTexture, int frames, float frameDuration, Rectf srcRect, bool isLooping = true);
~Animation() = default;
void Update(float elapsedSec);
void Draw(const Vector2f& pos) const;
void Draw(const Vector2f& pos, const Rectf& dst) const;
void SetPlaying(bool isPlaying) {
m_isPlaying = isPlaying;
}
void SetFlipped(bool isFlipped) {
m_isFlipped = isFlipped;
}
void Reset() {
m_CurrentFrame = 0;
m_hasPlayedOnce = false;
m_isPlaying = true;
m_FrameTimer = m_FrameDuration;
}
bool IsDone() const {
return m_hasPlayedOnce && !m_isLooping;
}
private:
Texture* m_pTexture;
Rectf m_SrcRect;
int m_Frames { 0 };
int m_CurrentFrame { 0 };
float m_FrameTimer { 0.0f };
float m_FrameDuration { 0.1f };
bool m_isPlaying { true };
bool m_isFlipped { false };
bool m_isLooping { true };
bool m_hasPlayedOnce { false };
};