mirror of
https://github.com/HowestDAE/dae16-VerhulstBram.git
synced 2026-02-04 10:49:21 +01:00
26 lines
678 B
C++
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);
|
|
}
|