Animation API getting better but now need to resolve how it works with the frames.
This commit is contained in:
parent
785d0240da
commit
d4e79f1d3d
7 changed files with 70 additions and 45 deletions
32
animate2.cpp
32
animate2.cpp
|
|
@ -4,7 +4,6 @@
|
|||
#include "dbc.hpp"
|
||||
#include "rand.hpp"
|
||||
|
||||
|
||||
namespace animate2 {
|
||||
std::vector<sf::IntRect> Animate2::calc_frames() {
|
||||
std::vector<sf::IntRect> frames;
|
||||
|
|
@ -53,7 +52,11 @@ namespace animate2 {
|
|||
if($sequence.timer.getElapsedTime() >= duration) {
|
||||
$sequence.timer.restart();
|
||||
$sequence.current++;
|
||||
if($sequence.subframe > 0.9) $sequence.subframe = 0.0f;
|
||||
frame_change = true;
|
||||
} else {
|
||||
$sequence.subframe = std::lerp($sequence.subframe, 1.0, $sequence.timer.alpha * $transform.ease_rate);
|
||||
fmt::println("subframe: {}, alpha: {}", $sequence.subframe, $sequence.timer.alpha);
|
||||
}
|
||||
|
||||
if($sequence.current >= $sequence.frame_count) {
|
||||
|
|
@ -67,12 +70,19 @@ namespace animate2 {
|
|||
}
|
||||
|
||||
void Animate2::update() {
|
||||
$sequence.subframe += $transform.speed;
|
||||
// $sequence.subframe += $transform.speed;
|
||||
update_frame();
|
||||
}
|
||||
|
||||
void Animate2::motion(sf::Vector2f& pos, sf::Vector2f& scale, float alpha) {
|
||||
$transform.lerp($sequence, pos, scale, alpha);
|
||||
void Animate2::motion(sf::Sprite& sprite, sf::Vector2f pos, sf::Vector2f scale) {
|
||||
$transform.lerp($sequence, pos, scale);
|
||||
|
||||
sprite.setPosition(pos);
|
||||
sprite.setScale(scale);
|
||||
}
|
||||
|
||||
std::pair<int, double> Animate2::commit() {
|
||||
return $sequence.timer.commit();
|
||||
}
|
||||
|
||||
void Timer::start() {
|
||||
|
|
@ -118,12 +128,14 @@ namespace animate2 {
|
|||
return {int(tick_count), alpha};
|
||||
}
|
||||
|
||||
float Transform::twitching(Sequence& seq, float alpha) {
|
||||
return easing(alpha);
|
||||
}
|
||||
void Transform::lerp(Sequence& seq, sf::Vector2f& pos_out, sf::Vector2f& scale_out) {
|
||||
// float dt = 1 - std::powf(ease_rate, seq.subframe + 0.0001);
|
||||
float tick = easing(seq.subframe);
|
||||
|
||||
void Transform::lerp(Sequence& seq, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float alpha) {
|
||||
float tick = std::abs(twitching(seq, alpha));
|
||||
return motion(*this, pos_out, scale_out, tick);
|
||||
motion(*this, pos_out, scale_out, tick);
|
||||
|
||||
fmt::println("sub: {}, tick: {}, tr: {},{}; pos: {},{}; scale: {},{}",
|
||||
seq.subframe, tick, min_y, max_y, pos_out.x, pos_out.y,
|
||||
scale_out.x, scale_out.y);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue