Finally have the boss fight rendering into a render texture correctly. The 'flipped' problem was because I didn't call .display() in render.

This commit is contained in:
Zed A. Shaw 2025-10-31 12:50:20 -04:00
parent 82a38e5fa1
commit 740e1052fe
6 changed files with 17 additions and 11 deletions

View file

@ -41,7 +41,6 @@ namespace components {
if(playing && current < frames) {
float tick = twitching();
fmt::print("tick: {}\r", tick);
if(stationary) {
switch(motion) {

View file

@ -8,8 +8,11 @@ namespace boss {
UI::UI(components::AnimatedScene& scene, Entity boss_id) :
$boss_id(boss_id),
$combat_ui(true),
$arena(scene)
$arena(scene),
$view_texture({BOSS_VIEW_WIDTH, BOSS_VIEW_HEIGHT}),
$view_sprite($view_texture.getTexture())
{
$view_sprite.setPosition({BOSS_VIEW_X, BOSS_VIEW_Y});
}
void UI::init() {
@ -37,13 +40,15 @@ namespace boss {
void UI::render(sf::RenderWindow& window) {
$actions.render(window);
$combat_ui.render(window);
$arena.render(window);
$arena.render($view_texture);
$view_texture.display();
window.draw($view_sprite);
}
bool UI::mouse(float x, float y, Modifiers mods) {
return $arena.mouse(x, y, mods)
|| $combat_ui.mouse(x, y, mods)
|| $actions.mouse(x, y, mods);
// BUG: arena is getting the _window_ coordinates, not the rendertexture
return $combat_ui.mouse(x, y, mods)
|| $actions.mouse(x, y, mods) || $arena.mouse(x, y, mods);
}
void UI::status(const std::wstring& msg) {

View file

@ -12,6 +12,8 @@ namespace boss {
gui::CombatUI $combat_ui;
scene::Engine $arena;
guecs::UI $actions;
sf::RenderTexture $view_texture;
sf::Sprite $view_sprite;
UI(components::AnimatedScene &scene, DinkyECS::Entity boss_id);

View file

@ -50,7 +50,7 @@ namespace scene {
}
void Engine::init() {
$ui.position(SCREEN_WIDTH-BOSS_VIEW_WIDTH,0, BOSS_VIEW_WIDTH, SCREEN_HEIGHT);
$ui.position(0,0, BOSS_VIEW_WIDTH, BOSS_VIEW_HEIGHT);
$ui.set<guecs::Background>($ui.MAIN, {$ui.$parser, guecs::THEME.TRANSPARENT});
auto& background = $ui.get<guecs::Background>($ui.MAIN);
background.set_sprite($scene.background, true);
@ -72,7 +72,7 @@ namespace scene {
return $ui.mouse(x, y, mods);
}
void Engine::render(sf::RenderWindow& window) {
void Engine::render(sf::RenderTarget& window) {
$ui.render(window);
for(auto& fixture : $fixtures) {

View file

@ -35,7 +35,7 @@ namespace scene {
Engine(components::AnimatedScene& scene);
void init();
void render(sf::RenderWindow& window);
void render(sf::RenderTarget& window);
bool mouse(float x, float y, guecs::Modifiers mods);
sf::Vector2f position_sprite(textures::SpriteTexture& st, const std::string& cell_name, float scale_x, float scale_y, bool at_mid, float x_diff=0.0f, float y_diff=0.0f);

View file

@ -1,6 +1,6 @@
[wrap-git]
directory=lel-guecs-0.6.0
url=https://git.learnjsthehardway.com/learn-code-the-hard-way/lel-guecs.git
directory=lel-guecs-0.7.0
url=https://git.zedshaw.games/games/lel-guecs.git
revision=HEAD
depth=1
method=meson