From 97f6a459eae05c326f4bd193ecdbf12de650dd3f Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sun, 29 Jun 2025 12:17:50 +0200 Subject: [PATCH] Title: optimitzat render() --- source/sections/title.cpp | 39 ++++++++++++++++++++++++++------------- source/sections/title.h | 11 +++++++++++ 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/source/sections/title.cpp b/source/sections/title.cpp index 925948e..833c643 100644 --- a/source/sections/title.cpp +++ b/source/sections/title.cpp @@ -50,6 +50,11 @@ Title::Title() const bool IS_TITLE_TO_DEMO = (Section::attract_mode == Section::AttractMode::TITLE_TO_DEMO); next_section_ = IS_TITLE_TO_DEMO ? Section::Name::GAME_DEMO : Section::Name::LOGO; Section::attract_mode = IS_TITLE_TO_DEMO ? Section::AttractMode::TITLE_TO_LOGO : Section::AttractMode::TITLE_TO_DEMO; + + // Define los anclajes de los elementos + anchor_.mini_logo = (param.game.height / 5 * 4) + BLOCK; + mini_logo_sprite_->setY(anchor_.mini_logo); + anchor_.copyright_text = anchor_.mini_logo + mini_logo_sprite_->getHeight() + 3; } // Destructor @@ -80,20 +85,9 @@ void Title::render() tiled_bg_->render(); game_logo_->render(); - - if (state_ != TitleState::LOGO_ANIMATING) - { - // Mini logo - const int pos1 = (param.game.height / 5 * 4) + BLOCK; - const int pos2 = pos1 + mini_logo_sprite_->getHeight() + 3; - mini_logo_sprite_->setY(pos1); - mini_logo_sprite_->render(); - - // Texto con el copyright - text_->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, pos2, TEXT_COPYRIGHT, 1, NO_TEXT_COLOR, 1, TITLE_SHADOW_TEXT_COLOR); - } - renderStartPrompt(); + renderCopyright(); + define_buttons_->render(); fade_->render(); @@ -377,4 +371,23 @@ void Title::renderStartPrompt() 1, TITLE_SHADOW_TEXT_COLOR); } +} + +void Title::renderCopyright() +{ + if (state_ != TitleState::LOGO_ANIMATING) + { + // Mini logo + mini_logo_sprite_->render(); + + // Texto con el copyright + text_->writeDX(TEXT_CENTER | TEXT_SHADOW, + param.game.game_area.center_x, + anchor_.copyright_text, + TEXT_COPYRIGHT, + 1, + NO_TEXT_COLOR, + 1, + TITLE_SHADOW_TEXT_COLOR); + } } \ No newline at end of file diff --git a/source/sections/title.h b/source/sections/title.h index d1baf1c..2043a7f 100644 --- a/source/sections/title.h +++ b/source/sections/title.h @@ -43,6 +43,13 @@ private: START_HAS_BEEN_PRESSED, // Se ha pulsado el botón de start }; + // --- Estructura para definir anclas --- + struct Anchor + { + int mini_logo; + int copyright_text; + }; + // --- Objetos y punteros --- std::shared_ptr text_; // Objeto de texto para escribir en pantalla std::unique_ptr fade_; // Fundido en pantalla @@ -60,6 +67,9 @@ private: TitleState state_; // Estado actual de la sección bool should_render_start_prompt = false; // Indica si se muestra o no el texto de PRESS START BUTTON TO PLAY + // -- Variables de diseño --- + Anchor anchor_; // Anclas para definir la posición de los elementos del titulo + // --- Métodos internos --- void update(); // Actualiza las variables del objeto void render(); // Dibuja el objeto en pantalla @@ -73,4 +83,5 @@ private: void updateState(); // Actualiza el estado void updateStartPrompt(); void renderStartPrompt(); + void renderCopyright(); }; \ No newline at end of file