-
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.
Сделал появление окна настройки анимации по нажатию на спрайт; Создал…
… класс настроек анимации Animator
- Loading branch information
Showing
5 changed files
with
175 additions
and
19 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
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,81 @@ | ||
#include <SFML/Graphics.hpp> | ||
#include "imgui.h" | ||
#include "imgui-SFML.h" | ||
#include "animator.h" | ||
|
||
namespace animation | ||
{ | ||
Animator::Animator(sf::RenderWindow* const window, AnimationClip* clip) | ||
{ | ||
m_window = window; | ||
m_clip = clip; | ||
m_animationIsSet = true; | ||
m_speed = clip->AnimSpeed(); | ||
m_path = ""; | ||
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_path = ""; | ||
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_path = ""; | ||
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("Pause")) | ||
m_clip->Pause(true); | ||
|
||
if (ImGui::Button("Unpause")) | ||
m_clip->Pause(false); | ||
|
||
ImGui::End(); | ||
} | ||
|
||
} | ||
} |
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,48 @@ | ||
#ifndef ANIMATOR_H_INCLUDED | ||
#define ANIMATOR_H_INCLUDED | ||
|
||
#include <SFML/Graphics.hpp> | ||
#include "animation.h" | ||
|
||
namespace animation | ||
{ | ||
class Animator | ||
{ | ||
private: | ||
sf::RenderWindow *m_window; // Игровое окно, к которому будет привязан UI инструмента | ||
AnimationClip *m_clip; // Анимация, над которой ведётся работа | ||
float m_speed; // Скорость анимации | ||
std::string m_path; // Путь к файлу со спрайтами | ||
sf::IntRect m_rect; // Размеры и координаты первого спрайта | ||
int m_countOfSprites; // Кол-во спрайтов в анимации | ||
bool m_animationIsSet; // Установлена ли анимация? | ||
|
||
public: | ||
// Конструктор аниматора | ||
// window - игровое окно, к которому будет привязан UI инструмента | ||
// clip - анимация, над которой ведётся работа | ||
Animator(sf::RenderWindow* const window, AnimationClip *clip); | ||
|
||
Animator(sf::RenderWindow* const window); | ||
|
||
// ImGui работает с выделением памяти, поэтому нужен явный декструктор | ||
~Animator(); | ||
|
||
// Обработчик событий | ||
void ProcessEvent(const sf::Event &event); | ||
|
||
// Рендер UI | ||
void Render(); | ||
|
||
// Установка новой анимации | ||
void SetAnimClip(AnimationClip *clip); | ||
|
||
// Обновление аниматора | ||
void Update(const sf::Time& deltaTime); | ||
|
||
const bool IsSet() const { return m_animationIsSet; } | ||
|
||
}; | ||
} | ||
|
||
#endif // ANIMATOR_H_INCLUDED |
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 |
---|---|---|
|
@@ -9,7 +9,7 @@ Size=405,127 | |
Collapsed=0 | ||
|
||
[Window][Animation Controller] | ||
Pos=332,45 | ||
Pos=311,86 | ||
Size=324,151 | ||
Collapsed=0 | ||
|
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