generated from avadae/minigin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
71a04bc
commit 105c5c4
Showing
10 changed files
with
130 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include "Animation.h" | ||
|
||
Fluffy::Animation::Animation(const glm::vec2& textureSize, int textureColumns, const int textureRows, float framesPerSecond) | ||
: m_TextureSize{ textureSize } | ||
, m_TextureColumns{ textureColumns } | ||
, m_TextureRows{ textureRows } | ||
, m_FramesPerSecond{ framesPerSecond } | ||
, m_SourceRect{ 0.0f, 0.0f, m_TextureSize.x / m_TextureColumns, m_TextureSize.y / m_TextureRows } | ||
{ | ||
|
||
} | ||
|
||
void Fluffy::Animation::Reset() | ||
{ | ||
m_SourceRect.left = 0.0f; | ||
m_SourceRect.top = 0.0f; | ||
|
||
m_CurrentFrame.x = 0; | ||
m_CurrentFrame.y = 0; | ||
m_AccumulatedSeconds = 0.0f; | ||
} | ||
|
||
void Fluffy::Animation::Update(float deltaTime) | ||
{ | ||
m_AccumulatedSeconds += deltaTime; | ||
|
||
if (m_AccumulatedSeconds >= (1.0f / m_FramesPerSecond)) | ||
{ | ||
m_AccumulatedSeconds = 0.0f; | ||
|
||
if (++m_CurrentFrame.x >= m_TextureColumns) | ||
{ | ||
m_CurrentFrame.x = 0.0f; | ||
|
||
if (++m_CurrentFrame.y >= m_TextureRows) | ||
{ | ||
m_CurrentFrame.y = 0.0f; | ||
} | ||
|
||
m_SourceRect.top = m_SourceRect.height * m_CurrentFrame.y; | ||
} | ||
|
||
m_SourceRect.left = m_SourceRect.width * m_CurrentFrame.x; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
#include "Rectf.h" | ||
#include "glm/glm.hpp" | ||
|
||
namespace Fluffy | ||
{ | ||
class Animation final | ||
{ | ||
public: | ||
Animation() = default; | ||
Animation(const glm::vec2& textureSize, int textureColumns, const int textureRows, float framesPerSecond); | ||
~Animation() = default; | ||
|
||
void Reset(); | ||
void Update(float elapsedSec); | ||
inline const Rectf& GetSourceRect() const { return m_SourceRect; } | ||
inline float GetDuration() const { return (m_TextureColumns * m_TextureRows) / m_FramesPerSecond; } | ||
inline bool HasFrames() const { return m_TextureColumns > 1 || m_TextureRows > 1; } | ||
|
||
private: | ||
glm::vec2 m_TextureSize{}; | ||
int m_TextureColumns{ 1 }; | ||
int m_TextureRows{ 1 }; | ||
Rectf m_SourceRect{}; | ||
float m_FramesPerSecond{ 8.0f }; | ||
float m_AccumulatedSeconds{ 0.0f }; | ||
glm::vec2 m_CurrentFrame{ 0.0f, 0.0f }; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters