Now can do a SLIDE motion that is a linear move to an x/y.

This commit is contained in:
Zed A. Shaw 2025-11-02 12:35:45 -05:00
parent f1f4cbc80f
commit 222c66a1f2
6 changed files with 58 additions and 48 deletions

View file

@ -35,46 +35,54 @@ namespace components {
}
}
void Animation::lerp(sf::Vector2f& scale_out, sf::Vector2f& pos_out) {
float tick = twitching();
if(stationary) {
switch(motion) {
case ease::SHAKE: {
pos_out.x += std::lerp(min_x, max_x, tick);
} break;
case ease::BOUNCE: {
pos_out.y -= std::lerp(min_y, max_y, tick);
} break;
case ease::RUSH: {
scale_out.x = std::lerp(min_x, max_x, tick);
scale_out.y = std::lerp(min_y, max_y, tick);
pos_out.y = pos_out.y - (pos_out.y * scale_out.y - pos_out.y);
} break;
case ease::SQUEEZE: {
scale_out.x *= std::lerp(min_x, max_x, tick);
} break;
case ease::SQUASH: {
scale_out.y *= std::lerp(min_y, max_y, tick);
} break;
case ease::STRETCH: {
scale_out.x = std::lerp(min_x, max_x, tick);
} break;
case ease::GROW: {
scale_out.y = std::lerp(min_y, max_y, tick);
} break;
case ease::SLIDE: {
pos_out.x += std::lerp(pos_out.x, pos_out.x + max_x, tick);
pos_out.y += std::lerp(pos_out.y, pos_out.y + max_y, tick);
} break;
default:
dbc::sentinel("Unknown animation.motion setting.");
}
} else {
scale_out.x = std::lerp(scale_out.x * min_x, scale_out.x * max_x, tick);
scale_out.y = std::lerp(scale_out.y * min_y, scale_out.y * max_y, tick);
}
}
void Animation::step(sf::Vector2f& scale_out, sf::Vector2f& pos_out, sf::IntRect& rect_out) {
dbc::check(rect_out.size.x > 0, "step given rect_out with size.x <= 0, must be >");
dbc::check(rect_out.size.y > 0, "step given rect_out with size.y <= 0, must be >");
if(playing && current < frames) {
float tick = twitching();
if(stationary) {
switch(motion) {
case ease::SHAKE: {
pos_out.x += std::lerp(min_x, max_x, tick);
} break;
case ease::BOUNCE: {
pos_out.y -= std::lerp(min_y, max_y, tick);
} break;
case ease::RUSH: {
scale_out.x = std::lerp(min_x, max_x, tick);
scale_out.y = std::lerp(min_y, max_y, tick);
pos_out.y = pos_out.y - (pos_out.y * scale_out.y - pos_out.y);
} break;
case ease::SQUEEZE: {
scale_out.x *= std::lerp(min_x, max_x, tick);
} break;
case ease::SQUASH: {
scale_out.y *= std::lerp(min_y, max_y, tick);
} break;
case ease::STRETCH: {
scale_out.x = std::lerp(min_x, max_x, tick);
} break;
case ease::GROW: {
scale_out.y = std::lerp(min_y, max_y, tick);
} break;
default:
dbc::sentinel("Unknown animation.motion setting.");
}
} else {
scale_out.x = std::lerp(scale_out.x * min_x, scale_out.x * max_x, tick);
scale_out.y = std::lerp(scale_out.y * min_y, scale_out.y * max_y, tick);
}
lerp(scale_out, pos_out);
if(!simple) {
rect_out.position.x += current * frame_width;
@ -91,8 +99,7 @@ namespace components {
rect_out.position.x += current * frame_width;
}
} else {
scale_out.x = min_x;
scale_out.y = min_y;
lerp(scale_out, pos_out);
playing = false;
current = 0;
subframe = 0.0f;
@ -112,7 +119,6 @@ namespace components {
sprite.setTextureRect(rect);
sprite.setPosition(pos);
// BUG: make this an option: apply_scale, apply_position and ranges for x y
if(scaled) {
sprite.setScale(scale);
}
@ -127,6 +133,7 @@ namespace components {
step(scale, pos, ignored);
view_out.setCenter(pos);
// BUG: is this also needed in the other apply?
if(scaled) {
view_out.setSize({size.x * scale.x, size.y * scale.y});
} else {