mirror of
https://github.com/HowestDAE/dae16-VerhulstBram.git
synced 2025-12-18 12:29:19 +01:00
Reformat + Basic animation system
General fixes
This commit is contained in:
25
Game/Animations/Animation.cpp
Normal file
25
Game/Animations/Animation.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#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);
|
||||
}
|
||||
Reference in New Issue
Block a user