Files
dae16-VerhulstBram-GameProject/Game/Animations/Animation.cpp
Bram Verhulst 9def986c83 Fix precompiled headers
Added edge detection (if it works :/)
2024-04-06 01:23:24 +02:00

27 lines
695 B
C++

#include "pch.h"
#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);
}