#include "pch.h"
#include "Animation.h"

#include "utils.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 Vector2f& pos) const {
	Draw(pos, Rectf{ pos.x, pos.y, m_SrcRect.width, m_SrcRect.height });
}

void Animation::Draw(const Vector2f& pos, const Rectf& dst) const {
	Rectf src = m_SrcRect;
	src.left += m_CurrentFrame * src.width;
	
	m_pTexture->Draw(dst, src, m_isFlipped);
}
