Added Sprite Coloring and Value Animations
This commit is contained in:
parent
e0e5298c81
commit
0cc5c0badf
11 changed files with 175 additions and 11 deletions
94
asloengine/animation.cpp
Normal file
94
asloengine/animation.cpp
Normal file
|
|
@ -0,0 +1,94 @@
|
||||||
|
#include "headers/animation.hpp"
|
||||||
|
|
||||||
|
namespace asloengine
|
||||||
|
{
|
||||||
|
|
||||||
|
Animation::Animation(Function _function, float _start_value, float _end_value, float _duration)
|
||||||
|
{
|
||||||
|
|
||||||
|
reset(_function, _start_value, _end_value, _duration);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Animation::reset(Function _function, float _start_value, float _end_value, float _duration)
|
||||||
|
{
|
||||||
|
|
||||||
|
function = _function;
|
||||||
|
start_value = _start_value;
|
||||||
|
current_value = _start_value;
|
||||||
|
end_value = _end_value;
|
||||||
|
time = 0;
|
||||||
|
duration = _duration;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
float Animation::animate(float delta_time)
|
||||||
|
{
|
||||||
|
|
||||||
|
time += delta_time;
|
||||||
|
|
||||||
|
if (time > duration)
|
||||||
|
{
|
||||||
|
time = duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (function)
|
||||||
|
{
|
||||||
|
|
||||||
|
case LINEAR:
|
||||||
|
return calculate_linear();
|
||||||
|
|
||||||
|
case EASE_IN:
|
||||||
|
return calculate_ease_in();
|
||||||
|
|
||||||
|
case EASE_OUT:
|
||||||
|
return calculate_ease_out();
|
||||||
|
|
||||||
|
case EASE_IN_OUT:
|
||||||
|
return calculate_ease_in_out();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
float Animation::calculate_linear()
|
||||||
|
{
|
||||||
|
|
||||||
|
float value_difference = end_value - start_value;
|
||||||
|
float progress = time / duration;
|
||||||
|
|
||||||
|
return start_value + value_difference * progress;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
float Animation::calculate_ease_in()
|
||||||
|
{
|
||||||
|
|
||||||
|
// TO-DO
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
float Animation::calculate_ease_out()
|
||||||
|
{
|
||||||
|
|
||||||
|
// TO-DO
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
float Animation::calculate_ease_in_out()
|
||||||
|
{
|
||||||
|
|
||||||
|
float value_difference = end_value - start_value;
|
||||||
|
float progress = time / duration;
|
||||||
|
|
||||||
|
progress = pow(progress, 2) / (pow(progress, 2) + pow((1 - progress), 2));
|
||||||
|
|
||||||
|
return (start_value + value_difference * progress);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
#include "framerate_counter.hpp"
|
#include "framerate_counter.hpp"
|
||||||
#include "scroll_view.hpp"
|
#include "scroll_view.hpp"
|
||||||
#include "grid_container.hpp"
|
#include "grid_container.hpp"
|
||||||
|
#include "../../headers/animation.hpp"
|
||||||
|
|
||||||
namespace asloengine
|
namespace asloengine
|
||||||
{
|
{
|
||||||
|
|
@ -20,6 +21,7 @@ namespace asloengine
|
||||||
|
|
||||||
sf::Texture button_texture;
|
sf::Texture button_texture;
|
||||||
sf::Font button_font;
|
sf::Font button_font;
|
||||||
|
Animation *test_animation;
|
||||||
|
|
||||||
void on_load() override;
|
void on_load() override;
|
||||||
void on_update(float delta_time) override;
|
void on_update(float delta_time) override;
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ namespace asloengine
|
||||||
toif->set_position(200, 300);
|
toif->set_position(200, 300);
|
||||||
|
|
||||||
InputField *if1 = new InputField("if_1", sf::Vector2f(200, 30), button_font, button_texture, 30, 20);
|
InputField *if1 = new InputField("if_1", sf::Vector2f(200, 30), button_font, button_texture, 30, 20);
|
||||||
if1->set_position(100, 420);
|
if1->set_position(0, 420);
|
||||||
if1->signal_on_focus.connect_member(to1, &TextObject::set_text, sf::String("gained focus"));
|
if1->signal_on_focus.connect_member(to1, &TextObject::set_text, sf::String("gained focus"));
|
||||||
if1->signal_on_lost_focus.connect_member(to1, &TextObject::set_text, sf::String("lost focus"));
|
if1->signal_on_lost_focus.connect_member(to1, &TextObject::set_text, sf::String("lost focus"));
|
||||||
//if1->signal_on_text_changed.connect_member(this, &SceneDefault::on_test);
|
//if1->signal_on_text_changed.connect_member(this, &SceneDefault::on_test);
|
||||||
|
|
@ -53,6 +53,8 @@ namespace asloengine
|
||||||
//if2->set_position(20, 20);
|
//if2->set_position(20, 20);
|
||||||
if2->signal_on_focus.connect_member(to1, &TextObject::set_text, sf::String("gained focus"));
|
if2->signal_on_focus.connect_member(to1, &TextObject::set_text, sf::String("gained focus"));
|
||||||
if2->signal_on_lost_focus.connect_member(to1, &TextObject::set_text, sf::String("lost focus"));
|
if2->signal_on_lost_focus.connect_member(to1, &TextObject::set_text, sf::String("lost focus"));
|
||||||
|
sf::Color *test_color = new sf::Color(192, 128, 96, 255);
|
||||||
|
if2->set_color(*test_color);
|
||||||
|
|
||||||
/*sc1->objects.emplace_back(if2);
|
/*sc1->objects.emplace_back(if2);
|
||||||
|
|
||||||
|
|
@ -73,10 +75,13 @@ namespace asloengine
|
||||||
|
|
||||||
|
|
||||||
base_layer.emplace_back(container);
|
base_layer.emplace_back(container);
|
||||||
|
base_layer.emplace_back(if1);
|
||||||
|
|
||||||
layers.emplace_back(base_layer);
|
layers.emplace_back(base_layer);
|
||||||
fixed_layers.emplace_back(gui_layer);
|
fixed_layers.emplace_back(gui_layer);
|
||||||
|
|
||||||
|
test_animation = new Animation(Animation::EASE_IN_OUT, 380, 200, 3);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneDefault::on_update(float delta_time)
|
void SceneDefault::on_update(float delta_time)
|
||||||
|
|
@ -84,6 +89,10 @@ namespace asloengine
|
||||||
|
|
||||||
//move_camera(sf::Vector2f(1, 2));
|
//move_camera(sf::Vector2f(1, 2));
|
||||||
|
|
||||||
|
float value = test_animation->animate(delta_time);
|
||||||
|
|
||||||
|
layers[0][1]->set_position(value, 420);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -42,6 +42,7 @@ namespace asloengine
|
||||||
PROGRAM_INFO, sf::Style::Close);
|
PROGRAM_INFO, sf::Style::Close);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
main_window->setPosition(_settings.window_position);
|
||||||
main_window->setVerticalSyncEnabled(active_settings.vsync_enabled);
|
main_window->setVerticalSyncEnabled(active_settings.vsync_enabled);
|
||||||
main_window->setFramerateLimit(active_settings.max_framerate);
|
main_window->setFramerateLimit(active_settings.max_framerate);
|
||||||
|
|
||||||
|
|
|
||||||
38
asloengine/headers/animation.hpp
Normal file
38
asloengine/headers/animation.hpp
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include "helpers.hpp"
|
||||||
|
|
||||||
|
namespace asloengine
|
||||||
|
{
|
||||||
|
|
||||||
|
class Animation
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum Function
|
||||||
|
{
|
||||||
|
LINEAR, EASE_IN, EASE_OUT, EASE_IN_OUT
|
||||||
|
};
|
||||||
|
|
||||||
|
Animation(Function _function, float _start_value, float _end_value, float _duration);
|
||||||
|
|
||||||
|
void reset(Function _function, float _start_value, float _end_value, float _duration);
|
||||||
|
float animate(float delta_time);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Function function;
|
||||||
|
float start_value;
|
||||||
|
float current_value;
|
||||||
|
float end_value;
|
||||||
|
float time;
|
||||||
|
float duration;
|
||||||
|
|
||||||
|
float calculate_linear();
|
||||||
|
float calculate_ease_in();
|
||||||
|
float calculate_ease_out();
|
||||||
|
float calculate_ease_in_out();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -15,6 +15,7 @@ namespace asloengine
|
||||||
uint resolution_y = 480;
|
uint resolution_y = 480;
|
||||||
uint bit_depth = 24;
|
uint bit_depth = 24;
|
||||||
uint max_framerate = 60;
|
uint max_framerate = 60;
|
||||||
|
sf::Vector2i window_position = sf::Vector2i(0, 0);
|
||||||
bool vsync_enabled = true;
|
bool vsync_enabled = true;
|
||||||
bool fullscreen_enabled = false;
|
bool fullscreen_enabled = false;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,8 @@ namespace asloengine
|
||||||
virtual ~SpriteObject() override;
|
virtual ~SpriteObject() override;
|
||||||
|
|
||||||
void load_texture(sf::Texture& _texture);
|
void load_texture(sf::Texture& _texture);
|
||||||
|
void set_color(sf::Color& _color);
|
||||||
|
sf::Color get_color() const;
|
||||||
virtual void draw() override;
|
virtual void draw() override;
|
||||||
virtual void on_main_property_update() override;
|
virtual void on_main_property_update() override;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,20 @@ namespace asloengine
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SpriteObject::set_color(sf::Color& _color)
|
||||||
|
{
|
||||||
|
|
||||||
|
sprite.setColor(_color);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
sf::Color SpriteObject::get_color() const
|
||||||
|
{
|
||||||
|
|
||||||
|
return sprite.getColor();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void SpriteObject::draw()
|
void SpriteObject::draw()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
||||||
18
log.txt
18
log.txt
|
|
@ -7,11 +7,13 @@
|
||||||
6 - LOG: GameObject 'if_2' has been Started
|
6 - LOG: GameObject 'if_2' has been Started
|
||||||
7 - LOG: GameObject 'Login Button' has been Started
|
7 - LOG: GameObject 'Login Button' has been Started
|
||||||
8 - LOG: GameObject 'Exit Button' has been Started
|
8 - LOG: GameObject 'Exit Button' has been Started
|
||||||
9 - LOG: Scene 'SceneDefault' has been Started
|
9 - LOG: GameObject 'if_1' has been Started
|
||||||
10 - LOG: GameObject 'Info Text' has been Destroyed
|
10 - LOG: Scene 'SceneDefault' has been Started
|
||||||
11 - LOG: GameObject 'if_2' has been Destroyed
|
11 - LOG: GameObject 'Info Text' has been Destroyed
|
||||||
12 - LOG: GameObject 'Login Button' has been Destroyed
|
12 - LOG: GameObject 'if_2' has been Destroyed
|
||||||
13 - LOG: GameObject 'Exit Button' has been Destroyed
|
13 - LOG: GameObject 'Login Button' has been Destroyed
|
||||||
14 - LOG: GameObject 'cont1' has been Destroyed
|
14 - LOG: GameObject 'Exit Button' has been Destroyed
|
||||||
15 - LOG: Scene 'SceneDefault' has been Destroyed
|
15 - LOG: GameObject 'cont1' has been Destroyed
|
||||||
16 - LOG: END Main Game Loop
|
16 - LOG: GameObject 'if_1' has been Destroyed
|
||||||
|
17 - LOG: Scene 'SceneDefault' has been Destroyed
|
||||||
|
18 - LOG: END Main Game Loop
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ int main()
|
||||||
480, // Resolution Y
|
480, // Resolution Y
|
||||||
24, // Bit Depth
|
24, // Bit Depth
|
||||||
60, // Max Framerate
|
60, // Max Framerate
|
||||||
|
sf::Vector2i(2000, 100), // Window Position
|
||||||
true, // Vsync Enabled
|
true, // Vsync Enabled
|
||||||
false // Fullscreen Enabled
|
false // Fullscreen Enabled
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
Color
|
ease-in function for Animation
|
||||||
Animations
|
ease-out function for Animation
|
||||||
Loading…
Add table
Add a link
Reference in a new issue