mirror of
https://github.com/HowestDAE/dae16-VerhulstBram.git
synced 2026-02-04 09:19:19 +01:00
Started on GuiIcon, General fixes
This commit is contained in:
@@ -4,7 +4,8 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "utils.h"
|
||||
Animation::Animation(Texture* pTexture, int frames, float frameDuration, Rectf srcRect, bool isLooping): m_pTexture(pTexture), m_SrcRect(srcRect), m_Frames(frames), m_isLooping(isLooping), m_FrameDuration(frameDuration) {
|
||||
Animation::Animation(Texture* pTexture, int frames, float frameDuration, Rectf srcRect, bool isLooping): m_pTexture(pTexture), m_SrcRect(srcRect), m_Frames(frames),
|
||||
m_isLooping(isLooping), m_FrameDuration(frameDuration) {
|
||||
|
||||
}
|
||||
void Animation::Update(float elapsedSec) {
|
||||
@@ -15,7 +16,7 @@ void Animation::Update(float elapsedSec) {
|
||||
++m_CurrentFrame;
|
||||
if (m_CurrentFrame >= m_Frames) {
|
||||
m_CurrentFrame = 0;
|
||||
if(!m_isLooping) {
|
||||
if (!m_isLooping) {
|
||||
m_hasPlayedOnce = true;
|
||||
m_isPlaying = false;
|
||||
}
|
||||
@@ -24,12 +25,33 @@ void Animation::Update(float elapsedSec) {
|
||||
}
|
||||
}
|
||||
void Animation::Draw(const Vector2f& pos) const {
|
||||
Draw(pos, Rectf{ pos.x, pos.y, m_SrcRect.width, m_SrcRect.height });
|
||||
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 += static_cast<float>(m_CurrentFrame) * src.width;
|
||||
|
||||
|
||||
m_pTexture->Draw(dst, src, m_isFlipped);
|
||||
}
|
||||
void Animation::SetPlaying(bool isPlaying) {
|
||||
m_isPlaying = isPlaying;
|
||||
}
|
||||
void Animation::SetFlipped(bool isFlipped) {
|
||||
m_isFlipped = isFlipped;
|
||||
}
|
||||
void Animation::Reset() {
|
||||
m_CurrentFrame = 0;
|
||||
m_hasPlayedOnce = false;
|
||||
m_isPlaying = true;
|
||||
m_FrameTimer = m_FrameDuration;
|
||||
}
|
||||
bool Animation::IsDone() const {
|
||||
return m_hasPlayedOnce && !m_isLooping;
|
||||
}
|
||||
int Animation::GetFrameCount() const {
|
||||
return m_Frames;
|
||||
}
|
||||
void Animation::SetFrame(int frame) {
|
||||
m_CurrentFrame = frame;
|
||||
}
|
||||
|
||||
@@ -5,29 +5,20 @@ class Animation
|
||||
{
|
||||
public:
|
||||
Animation(Texture* pTexture, int frames, float frameDuration, Rectf srcRect, bool isLooping = true);
|
||||
~Animation() = default;
|
||||
|
||||
void Update(float elapsedSec);
|
||||
void Draw(const Vector2f& pos) const;
|
||||
void Draw(const Vector2f& pos, const Rectf& dst) const;
|
||||
|
||||
|
||||
void SetPlaying(bool isPlaying) {
|
||||
m_isPlaying = isPlaying;
|
||||
}
|
||||
void SetFlipped(bool isFlipped) {
|
||||
m_isFlipped = isFlipped;
|
||||
}
|
||||
|
||||
void Reset() {
|
||||
m_CurrentFrame = 0;
|
||||
m_hasPlayedOnce = false;
|
||||
m_isPlaying = true;
|
||||
m_FrameTimer = m_FrameDuration;
|
||||
}
|
||||
bool IsDone() const {
|
||||
return m_hasPlayedOnce && !m_isLooping;
|
||||
}
|
||||
void SetPlaying(bool isPlaying);
|
||||
void SetFlipped(bool isFlipped);
|
||||
|
||||
void Reset();
|
||||
bool IsDone() const;
|
||||
|
||||
int GetFrameCount() const;
|
||||
void SetFrame(int frame);
|
||||
|
||||
private:
|
||||
Texture* m_pTexture;
|
||||
|
||||
Reference in New Issue
Block a user