Files
dae16-VerhulstBram-GameProject/Game/Animations/Animation.cpp
Bram Verhulst 0f9bb76973 Reformat + Basic animation system
General fixes
2024-04-01 10:27:37 +02:00

26 lines
678 B
C++

#include "Animation.h"
Animation::Animation(Texture* pTexture, int frames, float frameDuration, Rectf srcRect): m_pTexture(pTexture), m_SrcRect(srcRect), m_Frames(frames) {
}
Animation::~Animation() {
}
void Animation::Update(float elapsedSec) {
if (m_isPlaying) {
m_FrameTimer -= elapsedSec;
if (m_FrameTimer <= 0.0f) {
m_FrameTimer = 0.1f;
++m_CurrentFrame;
if (m_CurrentFrame >= m_Frames) {
m_CurrentFrame = 0;
}
}
}
}
void Animation::Draw(const Point2f& pos, float angle) const {
Rectf src = m_SrcRect;
src.left += m_CurrentFrame * src.width;
auto dst = Rectf { pos.x, pos.y, src.width, src.height };
m_pTexture->Draw(dst, src, m_isFlipped);
}