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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue