7
7
8
8
namespace Fluffy
9
9
{
10
- Sprite::Sprite (GameObject* pOwner, const std::string& fileName)
10
+ Sprite::Sprite (GameObject* pOwner, const std::string& fileName, const int textureColumns, const int textureRows, const float framesPerSecond )
11
11
: Component(pOwner)
12
12
{
13
+ glm::vec2 textureSize{};
14
+
13
15
if (!fileName.empty ())
16
+ {
14
17
m_pTexture = ResourceManager::GetInstance ().LoadTexture (fileName);
18
+ textureSize = m_pTexture->GetSize ();
19
+ }
20
+
21
+ m_Animation = Animation (textureSize, textureColumns, textureRows, framesPerSecond);
15
22
}
16
23
17
- Sprite::Sprite (class GameObject * pOwner, const std::string& fileName, const glm::vec2& offset)
18
- : Sprite(pOwner, fileName)
24
+ Sprite::Sprite (class GameObject * pOwner, const std::string& fileName, const glm::vec2& offset, const int textureColumns, const int textureRows, const float framesPerSecond )
25
+ : Sprite(pOwner, fileName, textureColumns, textureRows, framesPerSecond )
19
26
{
20
27
m_Offset = offset;
21
28
}
@@ -29,13 +36,20 @@ namespace Fluffy
29
36
};
30
37
}
31
38
39
+ void Sprite::Update (const float deltaTime)
40
+ {
41
+ if (m_Animation.HasFrames ())
42
+ m_Animation.Update (deltaTime);
43
+ }
44
+
32
45
void Sprite::Render () const
33
46
{
34
47
if (m_pTexture == nullptr )
35
48
return ;
36
49
37
- const auto & pos = m_pOwner->GetWorldPosition () - (m_pTexture->GetSize () * 0 .5f ) + m_Offset;
38
- Renderer::GetInstance ().RenderTexture (*m_pTexture, pos.x , pos.y );
50
+ const glm::vec2 size{ m_Animation.GetSourceRect ().width , m_Animation.GetSourceRect ().height };
51
+ const auto & pos = m_pOwner->GetWorldPosition () - (size * 0 .5f ) + m_Offset;
52
+ Renderer::GetInstance ().RenderTexture (*m_pTexture, m_Animation.GetSourceRect (), pos.x , pos.y );
39
53
}
40
54
41
55
void Sprite::SetTexture (const std::string& fileName)
0 commit comments