Torches are now flipped, but next is that same crash.
This commit is contained in:
parent
0e8b661273
commit
2484802d93
7 changed files with 23 additions and 32 deletions
22
scene.cpp
22
scene.cpp
|
|
@ -18,11 +18,12 @@ namespace scene {
|
|||
float y = config["y"];
|
||||
bool flipped = config["flipped"];
|
||||
|
||||
// BUG: need to make animation optional
|
||||
// BUG: put the .json file to load as a default/optional arg
|
||||
auto anim = animate2::load("./assets/animate2.json", sprite_name);
|
||||
anim.transform.flipped = flipped;
|
||||
if(and_play) anim.play();
|
||||
|
||||
anim.transform.flipped = flipped;
|
||||
|
||||
std::string cell = config["cell"];
|
||||
std::string name = config["name"];
|
||||
|
||||
|
|
@ -30,7 +31,7 @@ namespace scene {
|
|||
|
||||
sf::Text text(*$ui.$font, "", 60);
|
||||
|
||||
return {name, st, anim, cell, scale_x, scale_y, x, y, at_mid, flipped, nullptr, text};
|
||||
return {name, st, anim, cell, {scale_x, scale_y}, {x, y}, at_mid, flipped, nullptr, text};
|
||||
}
|
||||
|
||||
Engine::Engine(components::AnimatedScene& scene) :
|
||||
|
|
@ -64,12 +65,12 @@ namespace scene {
|
|||
|
||||
for(auto& actor : $actors) {
|
||||
actor.pos = position_sprite(actor.st, actor.cell,
|
||||
actor.scale_x, actor.scale_y, actor.at_mid, actor.x, actor.y);
|
||||
actor.scale, actor.at_mid, actor.pos.x, actor.pos.y);
|
||||
}
|
||||
|
||||
for(auto& fixture : $fixtures) {
|
||||
fixture.pos = position_sprite(fixture.st, fixture.cell,
|
||||
fixture.scale_x, fixture.scale_y, fixture.at_mid, fixture.x, fixture.y);
|
||||
fixture.scale, fixture.at_mid, fixture.pos.x, fixture.pos.y);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -81,7 +82,7 @@ namespace scene {
|
|||
void Engine::attach_text(const std::string& actor, const std::string& text) {
|
||||
auto& element = actor_config(actor);
|
||||
element.text.setPosition(element.pos);
|
||||
element.text.setScale({element.scale_x, element.scale_y});
|
||||
element.text.setScale(element.scale);
|
||||
element.text.setFillColor(sf::Color::Red);
|
||||
element.text.setOutlineThickness(2.0f);
|
||||
element.text.setOutlineColor(sf::Color::Black);
|
||||
|
|
@ -116,7 +117,7 @@ namespace scene {
|
|||
void Engine::move_actor(const std::string& actor, const std::string& cell_name) {
|
||||
auto& config = actor_config(actor);
|
||||
config.cell = cell_name;
|
||||
config.pos = position_sprite(config.st, config.cell, config.scale_x, config.scale_y, config.at_mid);
|
||||
config.pos = position_sprite(config.st, config.cell, config.scale, config.at_mid);
|
||||
}
|
||||
|
||||
void Engine::animate_actor(const std::string& actor) {
|
||||
|
|
@ -128,8 +129,8 @@ namespace scene {
|
|||
for(auto& fixture : $fixtures) {
|
||||
if(fixture.anim.playing) {
|
||||
fixture.anim.update();
|
||||
fixture.anim.motion(*fixture.st.sprite, fixture.pos, fixture.scale);
|
||||
fixture.anim.apply(*fixture.st.sprite);
|
||||
// REFACTOR: fixture.anim.apply(*fixture.st.sprite);
|
||||
} else {
|
||||
fixture.effect = nullptr;
|
||||
}
|
||||
|
|
@ -138,6 +139,7 @@ namespace scene {
|
|||
for(auto& actor : $actors) {
|
||||
if(actor.anim.playing) {
|
||||
actor.anim.update();
|
||||
actor.anim.motion(*actor.st.sprite, actor.pos, actor.scale);
|
||||
actor.anim.apply(*actor.st.sprite);
|
||||
// REFACTOR: actor.anim.apply(actor.text, actor.pos);
|
||||
// if(actor.effect != nullptr) actor.anim.apply_effect(actor.effect);
|
||||
|
|
@ -147,14 +149,14 @@ namespace scene {
|
|||
}
|
||||
}
|
||||
|
||||
sf::Vector2f Engine::position_sprite(textures::SpriteTexture& st, const std::string& cell_name, float scale_x, float scale_y, bool at_mid, float x_diff, float y_diff) {
|
||||
sf::Vector2f Engine::position_sprite(textures::SpriteTexture& st, const std::string& cell_name, sf::Vector2f scale, bool at_mid, float x_diff, float y_diff) {
|
||||
auto& cell = $ui.cell_for(cell_name);
|
||||
float x = float(at_mid ? cell.mid_x : cell.x);
|
||||
float y = float(at_mid ? cell.mid_y : cell.y);
|
||||
|
||||
sf::Vector2f pos{x + x_diff, y + y_diff};
|
||||
st.sprite->setPosition(pos);
|
||||
st.sprite->setScale({scale_x, scale_y});
|
||||
st.sprite->setScale(scale);
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue