Moved the text attaching code to the arena.
This commit is contained in:
parent
f50e713179
commit
0d23cf9537
5 changed files with 43 additions and 15 deletions
23
scene.cpp
23
scene.cpp
|
|
@ -5,7 +5,7 @@
|
|||
const bool DEBUG=false;
|
||||
|
||||
namespace scene {
|
||||
Element config_scene_element(nlohmann::json& config, bool and_play, bool duped) {
|
||||
Element Engine::config_scene_element(nlohmann::json& config, bool and_play, bool duped) {
|
||||
std::string sprite_name = config["sprite"];
|
||||
auto st = textures::get_sprite(sprite_name, duped);
|
||||
|
||||
|
|
@ -25,7 +25,9 @@ namespace scene {
|
|||
|
||||
bool at_mid = config["at_mid"];
|
||||
|
||||
return {name, st, anim, cell, scale_x, scale_y, x, y, at_mid, flipped};
|
||||
sf::Text text(*$ui.$font, "", 60);
|
||||
|
||||
return {name, st, anim, cell, scale_x, scale_y, x, y, at_mid, flipped, text};
|
||||
}
|
||||
|
||||
Engine::Engine(components::AnimatedScene& scene) :
|
||||
|
|
@ -68,6 +70,16 @@ 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.setFillColor(sf::Color::Red);
|
||||
element.text.setOutlineThickness(2.0f);
|
||||
element.text.setOutlineColor(sf::Color::Black);
|
||||
element.text.setString(text);
|
||||
}
|
||||
|
||||
bool Engine::mouse(float x, float y, guecs::Modifiers mods) {
|
||||
return $ui.mouse(x, y, mods);
|
||||
}
|
||||
|
|
@ -77,12 +89,15 @@ namespace scene {
|
|||
|
||||
for(auto& fixture : $fixtures) {
|
||||
window.draw(*fixture.st.sprite);
|
||||
window.draw(fixture.text);
|
||||
}
|
||||
|
||||
for(auto& actor : $actors) {
|
||||
window.draw(*actor.st.sprite);
|
||||
window.draw(actor.text);
|
||||
}
|
||||
|
||||
|
||||
if(DEBUG) $ui.debug_layout(window);
|
||||
}
|
||||
|
||||
|
|
@ -105,12 +120,16 @@ namespace scene {
|
|||
for(auto& fixture : $fixtures) {
|
||||
if(fixture.anim.playing) {
|
||||
fixture.anim.apply(*fixture.st.sprite, fixture.pos);
|
||||
fixture.text.setPosition(fixture.pos);
|
||||
fixture.text.setScale({fixture.scale_x, fixture.scale_y});
|
||||
}
|
||||
}
|
||||
|
||||
for(auto& actor : $actors) {
|
||||
if(actor.anim.playing) {
|
||||
actor.anim.apply(*actor.st.sprite, actor.pos);
|
||||
actor.text.setPosition(actor.pos);
|
||||
actor.text.setScale({actor.scale_x, actor.scale_y});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue