Compare commits
2 commits
102c8c36d5
...
f1f4cbc80f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f1f4cbc80f | ||
|
|
d60e1af6df |
10 changed files with 51 additions and 45 deletions
|
|
@ -102,6 +102,39 @@ namespace components {
|
|||
scale_out.x *= -1;
|
||||
}
|
||||
}
|
||||
|
||||
bool Animation::apply(sf::Sprite& sprite, sf::Vector2f pos) {
|
||||
sf::IntRect rect{{0,0}, {frame_width, frame_height}};
|
||||
sf::Vector2f scale{min_x, min_y};
|
||||
|
||||
step(scale, pos, rect);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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 {
|
||||
|
|
@ -111,23 +144,6 @@ namespace animation {
|
|||
static AnimationManager MGR;
|
||||
static bool initialized = false;
|
||||
|
||||
bool apply(Animation& anim, sf::Sprite& sprite, sf::Vector2f pos) {
|
||||
sf::IntRect rect{{0,0}, {anim.frame_width, anim.frame_height}};
|
||||
sf::Vector2f scale{anim.min_x, anim.min_y};
|
||||
|
||||
anim.step(scale, pos, rect);
|
||||
|
||||
sprite.setTextureRect(rect);
|
||||
sprite.setPosition(pos);
|
||||
|
||||
// BUG: make this an option: apply_scale, apply_position and ranges for x y
|
||||
if(anim.scaled) {
|
||||
sprite.setScale(scale);
|
||||
}
|
||||
|
||||
return anim.playing;
|
||||
}
|
||||
|
||||
void rotate(sf::Sprite& target, float degrees) {
|
||||
target.rotate(sf::degrees(degrees));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ namespace animation {
|
|||
std::unordered_map<std::string, components::Animation> animations;
|
||||
};
|
||||
|
||||
bool apply(components::Animation& anim, sf::Sprite& target, sf::Vector2f pos);
|
||||
void rotate(sf::Sprite& target, float degrees);
|
||||
void center(sf::Sprite& target, sf::Vector2f pos);
|
||||
|
||||
|
|
|
|||
|
|
@ -292,12 +292,12 @@
|
|||
"test_zoom": {
|
||||
"_type": "Animation",
|
||||
"easing": 6,
|
||||
"motion": 5,
|
||||
"motion": 6,
|
||||
"ease_rate": 0.5,
|
||||
"min_x": 1.0,
|
||||
"min_y": 1.0,
|
||||
"max_x": 1.2,
|
||||
"max_y": 1.2,
|
||||
"min_x": 0.8,
|
||||
"min_y": 0.9,
|
||||
"max_x": 1.1,
|
||||
"max_y": 1.1,
|
||||
"simple": true,
|
||||
"frames": 1,
|
||||
"speed": 0.01,
|
||||
|
|
|
|||
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,
|
||||
{float(cell.w * 2), float(cell.h * 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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
#include "point.hpp"
|
||||
#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>
|
||||
|
|
@ -138,6 +140,9 @@ namespace components {
|
|||
int frame_width = -1;
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ namespace gui {
|
|||
}
|
||||
|
||||
void MainUI::render_hands() {
|
||||
if(animation::apply($hand_anim, *$hand.sprite, {0,0})) {
|
||||
if($hand_anim.apply(*$hand.sprite, {0,0})) {
|
||||
$hand.sprite->setPosition({RAY_VIEW_X, RAY_VIEW_Y});
|
||||
$window.draw(*$hand.sprite);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ namespace gui {
|
|||
|
||||
void UI::OPENING(Event ev) {
|
||||
if(ev == Event::TICK) {
|
||||
if(!animation::apply($ritual_anim, *$ritual_ui.sprite, {0,0})) {
|
||||
if(!$ritual_anim.apply(*$ritual_ui.sprite, {0,0})) {
|
||||
state(State::OPENED);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,13 +100,13 @@ namespace scene {
|
|||
void Engine::play_animations() {
|
||||
for(auto& fixture : $fixtures) {
|
||||
if(fixture.anim.playing) {
|
||||
animation::apply(fixture.anim, *fixture.st.sprite, fixture.pos);
|
||||
fixture.anim.apply(*fixture.st.sprite, fixture.pos);
|
||||
}
|
||||
}
|
||||
|
||||
for(auto& actor : $actors) {
|
||||
if(actor.anim.playing) {
|
||||
animation::apply(actor.anim, *actor.st.sprite, actor.pos);
|
||||
actor.anim.apply(*actor.st.sprite, actor.pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ TEST_CASE("animation utility API", "[animation]") {
|
|||
|
||||
anim.play();
|
||||
|
||||
while(animation::apply(anim, *blanket.sprite, {0,0})) {
|
||||
while(anim.apply(*blanket.sprite, {0,0})) {
|
||||
fmt::println("animation: {}", anim.subframe);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ struct AnimationState {
|
|||
}
|
||||
|
||||
void apply(textures::SpriteTexture& st) {
|
||||
animation::apply(anim, *st.sprite, pos);
|
||||
anim.apply(*st.sprite, pos);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue