Movement is now much smoother for the easing functions and I can pan around better, but it's hard coded to only do pan at the moment.
This commit is contained in:
parent
2ebefcce05
commit
0d326089f7
8 changed files with 37 additions and 47 deletions
|
|
@ -1,7 +1,9 @@
|
|||
#include "animation.hpp"
|
||||
#include "rand.hpp"
|
||||
#include <cmath>
|
||||
|
||||
namespace components {
|
||||
|
||||
void Animation::play() {
|
||||
if(!playing) {
|
||||
current = 0;
|
||||
|
|
@ -11,7 +13,7 @@ namespace components {
|
|||
}
|
||||
|
||||
float Animation::twitching() {
|
||||
float tick = ease::sine(float(frames) / (subframe + 0.0001) * ease_rate);
|
||||
float tick = 1 - std::powf(ease_rate, subframe + 0.0001);
|
||||
|
||||
switch(easing) {
|
||||
case ease::NONE:
|
||||
|
|
@ -21,13 +23,15 @@ namespace components {
|
|||
case ease::OUT_CIRC:
|
||||
return ease::out_circ(tick);
|
||||
case ease::OUT_BOUNCE:
|
||||
return ease::sine(ease::out_bounce(tick));
|
||||
return ease::out_bounce(tick);
|
||||
case ease::IN_OUT_BACK:
|
||||
return ease::sine(ease::in_out_back(tick));
|
||||
return ease::in_out_back(tick);
|
||||
case ease::RANDOM:
|
||||
return Random::uniform_real(0.0001f, 1.0f);
|
||||
case ease::NORM_DIST:
|
||||
return Random::normal(0.5f, 0.1f);
|
||||
case ease::LINEAR:
|
||||
return tick;
|
||||
default:
|
||||
dbc::sentinel(
|
||||
fmt::format("Invalid easing {} given to animation",
|
||||
|
|
@ -65,8 +69,8 @@ namespace components {
|
|||
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);
|
||||
pos_out.x = std::lerp(min_x, max_x, tick);
|
||||
pos_out.y = std::lerp(min_y, max_y, tick);
|
||||
} break;
|
||||
default:
|
||||
dbc::sentinel("Unknown animation.motion setting.");
|
||||
|
|
|
|||
|
|
@ -156,7 +156,7 @@
|
|||
"max_y": 1.2,
|
||||
"simple": true,
|
||||
"frames": 1,
|
||||
"speed": 0.6,
|
||||
"speed": 0.2,
|
||||
"scaled": true,
|
||||
"stationary": false,
|
||||
"toggled": false,
|
||||
|
|
@ -192,7 +192,7 @@
|
|||
"max_y": 1.1,
|
||||
"simple": true,
|
||||
"frames": 10,
|
||||
"speed": 1.0,
|
||||
"speed": 0.2,
|
||||
"scaled": true,
|
||||
"stationary": false,
|
||||
"toggled": false,
|
||||
|
|
@ -235,24 +235,6 @@
|
|||
"flipped": false,
|
||||
"looped": false
|
||||
},
|
||||
"rat_king_boss": {
|
||||
"_type": "Animation",
|
||||
"easing": 4,
|
||||
"motion": 0,
|
||||
"ease_rate": 0.5,
|
||||
"min_x": 0.6,
|
||||
"min_y": 0.6,
|
||||
"max_x": 0.8,
|
||||
"max_y": 0.8,
|
||||
"simple": false,
|
||||
"frames": 2,
|
||||
"speed": 0.02,
|
||||
"scaled": true,
|
||||
"stationary": true,
|
||||
"toggled": false,
|
||||
"flipped": false,
|
||||
"looped": false
|
||||
},
|
||||
"torch_fixture": {
|
||||
"_type": "Animation",
|
||||
"easing": 0,
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"pan": {
|
||||
"_type": "Animation",
|
||||
"easing": 2,
|
||||
"easing": 7,
|
||||
"motion": 7,
|
||||
"ease_rate": 0.05,
|
||||
"min_x": 0,
|
||||
"min_y": 0,
|
||||
"max_x": 150.0,
|
||||
"ease_rate": 0.001,
|
||||
"min_x": 0.0,
|
||||
"min_y": 0.0,
|
||||
"max_x": 0.0,
|
||||
"max_y": 0.0,
|
||||
"simple": true,
|
||||
"frames": 1,
|
||||
|
|
@ -40,8 +40,8 @@
|
|||
"easing": 1,
|
||||
"motion": 0,
|
||||
"ease_rate": 0.5,
|
||||
"min_x": 1.3,
|
||||
"min_y": 1.3,
|
||||
"min_x": 0.8,
|
||||
"min_y": 0.8,
|
||||
"max_x": 1.0,
|
||||
"max_y": 1.0,
|
||||
"simple": true,
|
||||
|
|
|
|||
|
|
@ -40,8 +40,15 @@ namespace cinematic {
|
|||
anim = MGR.animations.at(name);
|
||||
}
|
||||
|
||||
void Camera::position(float x, float y) {
|
||||
anim.min_x = x;
|
||||
anim.min_y = y;
|
||||
}
|
||||
|
||||
void Camera::move(sf::RenderTexture& target, sf::Vector2f pos) {
|
||||
sf::View zoom;
|
||||
anim.max_x = pos.x;
|
||||
anim.max_y = pos.y;
|
||||
anim.apply(zoom, pos, size);
|
||||
target.setView(zoom);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ namespace cinematic {
|
|||
void move(sf::RenderTexture& target, sf::Vector2f pos);
|
||||
bool playing();
|
||||
void play();
|
||||
void position(float x, float y);
|
||||
void style(const std::string &name);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,8 @@ namespace ease {
|
|||
OUT_BOUNCE=3,
|
||||
IN_OUT_BACK=4,
|
||||
RANDOM=5,
|
||||
NORM_DIST=6
|
||||
NORM_DIST=6,
|
||||
LINEAR=7
|
||||
};
|
||||
|
||||
enum Motion {
|
||||
|
|
|
|||
|
|
@ -3,13 +3,12 @@
|
|||
#include "animation.hpp"
|
||||
|
||||
namespace storyboard {
|
||||
|
||||
UI::UI() :
|
||||
$view_texture({SCREEN_WIDTH, SCREEN_HEIGHT}),
|
||||
$view_sprite($view_texture.getTexture())
|
||||
{
|
||||
$view_sprite.setPosition({0, 0});
|
||||
$camera.style("dolly");
|
||||
$camera.style("pan");
|
||||
}
|
||||
|
||||
void UI::init() {
|
||||
|
|
@ -31,6 +30,7 @@ namespace storyboard {
|
|||
zoom($zoom_target);
|
||||
}
|
||||
|
||||
$view_texture.clear();
|
||||
$ui.render($view_texture);
|
||||
$ui.debug_layout($view_texture);
|
||||
$view_texture.display();
|
||||
|
|
@ -38,17 +38,13 @@ namespace storyboard {
|
|||
}
|
||||
|
||||
bool UI::mouse(float x, float y, guecs::Modifiers mods) {
|
||||
auto& cell = $ui.cell_for($zoom_target);
|
||||
$camera.position(cell.mid_x, cell.mid_y);
|
||||
|
||||
if(zoomed) {
|
||||
zoomed = false;
|
||||
reset();
|
||||
} else {
|
||||
zoomed = true;
|
||||
auto target = $ui.$parser.hit(x, y);
|
||||
$zoom_target = *target;
|
||||
zoom($zoom_target);
|
||||
$camera.play();
|
||||
}
|
||||
$zoom_target = *$ui.$parser.hit(x, y);
|
||||
|
||||
zoom($zoom_target);
|
||||
$camera.play();
|
||||
|
||||
return $ui.mouse(x, y, mods);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,8 +10,7 @@ namespace storyboard {
|
|||
sf::RenderTexture $view_texture;
|
||||
sf::Sprite $view_sprite;
|
||||
cinematic::Camera $camera;
|
||||
std::string $zoom_target;
|
||||
bool zoomed = false;
|
||||
std::string $zoom_target = "a";
|
||||
|
||||
UI();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue