Animations can now be applied to sf::View to do animated camera effects.
This commit is contained in:
parent
d60e1af6df
commit
f1f4cbc80f
4 changed files with 27 additions and 22 deletions
|
|
@ -119,6 +119,22 @@ namespace components {
|
|||
|
||||
return playing;
|
||||
}
|
||||
|
||||
bool Animation::apply(sf::View& view_out, sf::Vector2f pos, sf::Vector2f size) {
|
||||
sf::Vector2f scale{min_x, min_y};
|
||||
sf::IntRect ignored{{0,0}, {int(size.x), int(size.y)}};
|
||||
|
||||
step(scale, pos, ignored);
|
||||
view_out.setCenter(pos);
|
||||
|
||||
if(scaled) {
|
||||
view_out.setSize({size.x * scale.x, size.y * scale.y});
|
||||
} else {
|
||||
view_out.setSize(size);
|
||||
}
|
||||
|
||||
return playing;
|
||||
}
|
||||
}
|
||||
|
||||
namespace animation {
|
||||
|
|
|
|||
|
|
@ -292,16 +292,16 @@
|
|||
"test_zoom": {
|
||||
"_type": "Animation",
|
||||
"easing": 6,
|
||||
"motion": 1,
|
||||
"motion": 6,
|
||||
"ease_rate": 0.5,
|
||||
"min_x": -10.0,
|
||||
"min_y": -10.0,
|
||||
"max_x": 10.0,
|
||||
"max_y": 10.0,
|
||||
"min_x": 0.8,
|
||||
"min_y": 0.9,
|
||||
"max_x": 1.1,
|
||||
"max_y": 1.1,
|
||||
"simple": true,
|
||||
"frames": 1,
|
||||
"speed": 0.01,
|
||||
"scaled": false,
|
||||
"scaled": true,
|
||||
"stationary": true,
|
||||
"toggled": false,
|
||||
"flipped": false,
|
||||
|
|
|
|||
18
boss/ui.cpp
18
boss/ui.cpp
|
|
@ -81,23 +81,9 @@ namespace boss {
|
|||
$view_texture.setView(zoom);
|
||||
} else if($zoom_anim.playing) {
|
||||
auto& cell = $arena.$ui.cell_for(cell_name);
|
||||
sf::Vector2f scale{$zoom_anim.min_x, $zoom_anim.min_y};
|
||||
sf::Vector2f pos{float(cell.x), float(cell.y)};
|
||||
sf::IntRect rect{{0,0}, {cell.w, cell.h}};
|
||||
|
||||
$zoom_anim.step(scale, pos, rect);
|
||||
fmt::println("SCALE: {},{}; pos: {},{}; rect: {},{};{},{}",
|
||||
scale.x, scale.y, pos.x, pos.y,
|
||||
rect.position.x, rect.position.y,
|
||||
rect.size.x, rect.size.y);
|
||||
|
||||
sf::View zoom{pos,
|
||||
{BOSS_VIEW_WIDTH/2, BOSS_VIEW_HEIGHT/2}};
|
||||
|
||||
if($zoom_anim.scaled) {
|
||||
zoom.zoom(scale.x);
|
||||
}
|
||||
|
||||
sf::View zoom;
|
||||
$zoom_anim.apply(zoom, pos, {BOSS_VIEW_WIDTH/2, BOSS_VIEW_HEIGHT/2});
|
||||
$view_texture.setView(zoom);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#include <SFML/Graphics/Rect.hpp>
|
||||
#include <SFML/Graphics/Shader.hpp>
|
||||
#include <SFML/Graphics/Sprite.hpp>
|
||||
#include <SFML/Graphics/View.hpp>
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
|
|
@ -140,6 +141,8 @@ namespace components {
|
|||
int frame_height = -1;
|
||||
|
||||
bool apply(sf::Sprite& target, sf::Vector2f pos);
|
||||
bool apply(sf::View& view_out, sf::Vector2f pos, sf::Vector2f size);
|
||||
|
||||
void play();
|
||||
float twitching();
|
||||
void step(sf::Vector2f& scale_out, sf::Vector2f& pos_out, sf::IntRect& rect_out);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue