All of the original features now work: simple, flipped, scaled, toggled, looped and stationary is replaced by ease2::scale_only.
This commit is contained in:
parent
34e4a34f65
commit
ca335d21e5
4 changed files with 25 additions and 11 deletions
|
|
@ -35,6 +35,8 @@ namespace animate2 {
|
||||||
// need one for each kind of thing to animate
|
// need one for each kind of thing to animate
|
||||||
// NOTE: possibly find a way to only run apply on frame change?
|
// NOTE: possibly find a way to only run apply on frame change?
|
||||||
void Animate2::apply(sf::Sprite& sprite) {
|
void Animate2::apply(sf::Sprite& sprite) {
|
||||||
|
dbc::check(!$transform.simple, "can't call ::apply() on a simple animation, only ::motion()");
|
||||||
|
|
||||||
dbc::check($sequence.current < $frame_rects.size(), "current frame past $frame_rects");
|
dbc::check($sequence.current < $frame_rects.size(), "current frame past $frame_rects");
|
||||||
// NOTE: pos is not updated yet
|
// NOTE: pos is not updated yet
|
||||||
auto& rect = $frame_rects.at($sequence.current);
|
auto& rect = $frame_rects.at($sequence.current);
|
||||||
|
|
@ -76,9 +78,16 @@ namespace animate2 {
|
||||||
void Animate2::motion(sf::Sprite& sprite, sf::Vector2f pos, sf::Vector2f scale) {
|
void Animate2::motion(sf::Sprite& sprite, sf::Vector2f pos, sf::Vector2f scale) {
|
||||||
$transform.lerp($sequence, pos, scale);
|
$transform.lerp($sequence, pos, scale);
|
||||||
|
|
||||||
|
if($transform.flipped) {
|
||||||
|
scale.x *= -1;
|
||||||
|
}
|
||||||
|
|
||||||
sprite.setPosition(pos);
|
sprite.setPosition(pos);
|
||||||
|
|
||||||
|
if($transform.scaled) {
|
||||||
sprite.setScale(scale);
|
sprite.setScale(scale);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::pair<int, double> Animate2::commit() {
|
std::pair<int, double> Animate2::commit() {
|
||||||
return $sequence.timer.commit();
|
return $sequence.timer.commit();
|
||||||
|
|
|
||||||
|
|
@ -53,8 +53,8 @@ namespace animate2 {
|
||||||
bool flipped{false};
|
bool flipped{false};
|
||||||
float ease_rate{0.5f};
|
float ease_rate{0.5f};
|
||||||
bool scaled{false};
|
bool scaled{false};
|
||||||
bool stationary{false};
|
|
||||||
// these can handled by the onLoop, same as ganim8 does it
|
// handled by onLoop
|
||||||
bool toggled{false};
|
bool toggled{false};
|
||||||
bool looped{false};
|
bool looped{false};
|
||||||
|
|
||||||
|
|
@ -71,7 +71,12 @@ namespace animate2 {
|
||||||
using OnFrameHandler = std::function<void()>;
|
using OnFrameHandler = std::function<void()>;
|
||||||
|
|
||||||
inline bool DefaultOnLoop(Sequence& seq, Transform& tr) {
|
inline bool DefaultOnLoop(Sequence& seq, Transform& tr) {
|
||||||
|
if(tr.toggled) {
|
||||||
|
seq.current = seq.frame_count - 1;
|
||||||
|
} else {
|
||||||
seq.current = 0;
|
seq.current = 0;
|
||||||
|
}
|
||||||
|
|
||||||
return tr.looped;
|
return tr.looped;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,6 @@ Animate2 crafter() {
|
||||||
.flipped{false},
|
.flipped{false},
|
||||||
.ease_rate{0.5f},
|
.ease_rate{0.5f},
|
||||||
.scaled{true},
|
.scaled{true},
|
||||||
.stationary{true},
|
|
||||||
.toggled{false},
|
.toggled{false},
|
||||||
.looped{false},
|
.looped{false},
|
||||||
.easing = ease2::in_out_back,
|
.easing = ease2::in_out_back,
|
||||||
|
|
|
||||||
|
|
@ -169,11 +169,10 @@ animate2::Transform scale_tr{
|
||||||
.flipped{false},
|
.flipped{false},
|
||||||
.ease_rate{1.0f/0.2f},
|
.ease_rate{1.0f/0.2f},
|
||||||
.scaled{true},
|
.scaled{true},
|
||||||
.stationary{true},
|
|
||||||
.toggled{false},
|
.toggled{false},
|
||||||
.looped{true},
|
.looped{true},
|
||||||
.easing = ease2::in_out_back,
|
.easing = ease2::in_out_back,
|
||||||
.motion = ease2::move_rush,
|
.motion = ease2::scale_only,
|
||||||
};
|
};
|
||||||
|
|
||||||
animate2::Transform move_tr{
|
animate2::Transform move_tr{
|
||||||
|
|
@ -185,7 +184,6 @@ animate2::Transform move_tr{
|
||||||
.flipped{false},
|
.flipped{false},
|
||||||
.ease_rate{2.5f},
|
.ease_rate{2.5f},
|
||||||
.scaled{true},
|
.scaled{true},
|
||||||
.stationary{true},
|
|
||||||
.toggled{false},
|
.toggled{false},
|
||||||
.looped{true},
|
.looped{true},
|
||||||
.easing = ease2::normal_dist,
|
.easing = ease2::normal_dist,
|
||||||
|
|
@ -223,10 +221,13 @@ int main(int argc, char* argv[]) {
|
||||||
|
|
||||||
for(int i = 0; i < ticks; i++) {
|
for(int i = 0; i < ticks; i++) {
|
||||||
main.event(game::Event::TICK, {});
|
main.event(game::Event::TICK, {});
|
||||||
|
|
||||||
|
if(anim.playing) {
|
||||||
anim.update();
|
anim.update();
|
||||||
anim.apply(*sprite);
|
anim.apply(*sprite);
|
||||||
anim.motion(*sprite, pos, scale);
|
anim.motion(*sprite, pos, scale);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
main.render();
|
main.render();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue