Animations now have an easing/ease_rate setting that will do a dynamic scaling effect on them during the animation sequence.
This commit is contained in:
parent
6e363ba78d
commit
033358749f
8 changed files with 42 additions and 14 deletions
|
@ -1,5 +1,6 @@
|
|||
#include "components.hpp"
|
||||
#include "point.hpp"
|
||||
#include "easings.hpp"
|
||||
|
||||
namespace components {
|
||||
ENROLL_COMPONENT(Position, location.x, location.y);
|
||||
|
@ -7,7 +8,7 @@ namespace components {
|
|||
ENROLL_COMPONENT(Motion, dx, dy, random);
|
||||
ENROLL_COMPONENT(Combat, hp, max_hp, damage, dead);
|
||||
ENROLL_COMPONENT(Device, config, events);
|
||||
ENROLL_COMPONENT(Animation, scale, simple, frames, speed);
|
||||
ENROLL_COMPONENT(Animation, scale, simple, frames, speed, easing, ease_rate);
|
||||
ENROLL_COMPONENT(Sound, attack, death);
|
||||
|
||||
void configure_entity(const ComponentMap& component_map, DinkyECS::World& world, DinkyECS::Entity ent, json& data) {
|
||||
|
@ -41,11 +42,28 @@ namespace components {
|
|||
}
|
||||
}
|
||||
|
||||
float Animation::twitching() {
|
||||
switch(easing) {
|
||||
case ease::SINE:
|
||||
return ease::sine(float(frames) / subframe * ease_rate);
|
||||
case ease::OUT_CIRC:
|
||||
return ease::sine(ease::out_circ(float(frames) / subframe * ease_rate));
|
||||
case ease::OUT_BOUNCE:
|
||||
return ease::sine(ease::out_bounce(float(frames) / subframe * ease_rate));
|
||||
case ease::IN_OUT_BACK:
|
||||
return ease::sine(ease::in_out_back(float(frames) / subframe * ease_rate));
|
||||
default:
|
||||
dbc::sentinel(
|
||||
fmt::format("Invalid easing {} given to animation",
|
||||
int(easing)));
|
||||
}
|
||||
}
|
||||
|
||||
void Animation::step(sf::Vector2f& scale_out, sf::IntRect& rect_out) {
|
||||
if(playing && current < frames) {
|
||||
scale_out.x += scale;
|
||||
scale_out.y += scale;
|
||||
|
||||
float tick = twitching();
|
||||
scale_out.x = std::lerp(scale_out.x, scale_out.x + scale, tick);
|
||||
scale_out.y = std::lerp(scale_out.y, scale_out.y + scale, tick);
|
||||
if(!simple) {
|
||||
rect_out.position.x += current * TEXTURE_WIDTH;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue