-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimator.cpp
88 lines (73 loc) · 1.78 KB
/
animator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <SFML/Graphics.hpp>
#include "imgui.h"
#include "imgui-SFML.h"
#include "animator.h"
#include <cstring>
namespace animation
{
Animator::Animator(sf::RenderWindow* const window, AnimationClip* clip)
{
m_window = window;
m_clip = clip;
m_animationIsSet = true;
m_speed = clip->AnimSpeed();
m_rect = sf::IntRect(0,0,0,0);
m_countOfSprites = clip->NumberOfSprites();
ImGui::SFML::Init(*m_window);
}
Animator::Animator(sf::RenderWindow* const window)
{
m_window = window;
m_clip = NULL;
m_animationIsSet = false;
m_speed = 0;
m_rect = sf::IntRect(0,0,0,0);
m_countOfSprites = 0;
ImGui::SFML::Init(*m_window);
}
Animator::~Animator()
{
ImGui::SFML::Shutdown();
}
void Animator::ProcessEvent(const sf::Event& event)
{
ImGui::SFML::ProcessEvent(event);
}
void Animator::Render()
{
if (m_window != NULL && m_clip != NULL)
ImGui::SFML::Render(*m_window);
}
void Animator::SetAnimClip(AnimationClip* clip)
{
m_clip = clip;
m_animationIsSet = true;
m_speed = clip->AnimSpeed();
m_rect = sf::IntRect(0,0,0,0);
m_countOfSprites = clip->NumberOfSprites();
ImGui::SFML::Init(*m_window);
}
void Animator::Update(const sf::Time& deltaTime)
{
if (m_window != NULL && m_clip != NULL)
{
ImGui::SFML::Update(*m_window, deltaTime);
ImGui::Begin("Animation Controller");
ImGui::Text("Speed of animation");
if (ImGui::DragFloat("Speed", &m_speed, 0.1f, 0.0f, 5.0f))
m_clip->SetAnimSpeed(m_speed);
if (ImGui::Button("Start"))
m_clip->Restart();
ImGui::SameLine();
if (ImGui::Button("Pause"))
m_clip->Pause(true);
ImGui::SameLine();
if (ImGui::Button("Unpause"))
m_clip->Pause(false);
static bool loop = true;
if (ImGui::Checkbox("Loop", &loop))
m_clip->SetLoop(loop);
ImGui::End();
}
}
}