migrat hiscore_table a delta_time de manera correcta

corregida deformació subpixel de la textura en instructions i hiscore_table
This commit is contained in:
2025-10-24 08:49:09 +02:00
parent 1acbe1d097
commit 1c3d59d678
4 changed files with 9 additions and 7 deletions

View File

@@ -44,7 +44,7 @@ Director::Director(int argc, std::span<char*> argv) {
Section::name = Section::Name::GAME;
Section::options = Section::Options::GAME_PLAY_1P;
#elif _DEBUG
Section::name = Section::Name::INSTRUCTIONS;
Section::name = Section::Name::HI_SCORE_TABLE;
Section::options = Section::Options::GAME_PLAY_1P;
#else // NORMAL GAME
Section::name = Section::Name::LOGO;

View File

@@ -74,11 +74,11 @@ void HiScoreTable::render() {
SCREEN->start(); // Prepara para empezar a dibujar en la textura de juego
SCREEN->clean(); // Limpia la pantalla
background_->render(); // Pinta el fondo
float counter_equivalent = elapsed_time_ * 60.0F; // Convertir tiempo a equivalente frame para UI
view_area_.y = std::max(0.0F, param.game.height - counter_equivalent + 100); // Establece la ventana del backbuffer
SDL_RenderTexture(renderer_, backbuffer_, nullptr, &view_area_); // Copia el backbuffer al renderizador
fade_->render(); // Renderiza el fade
background_->render(); // Pinta el fondo
float scroll_offset = elapsed_time_ * SCROLL_SPEED_PPS; // Calcula el desplazamiento del scroll usando velocidad en pixels/segundo
view_area_.y = std::round(std::max(0.0F, (param.game.height + 100.0F) - scroll_offset)); // Establece la ventana del backbuffer (redondeado para evitar deformaciones)
SDL_RenderTexture(renderer_, backbuffer_, nullptr, &view_area_); // Copia el backbuffer al renderizador
fade_->render(); // Renderiza el fade
SCREEN->render(); // Vuelca el contenido del renderizador en pantalla
}

View File

@@ -38,6 +38,7 @@ class HiScoreTable {
static constexpr float BACKGROUND_CHANGE_S = 150.0F / 60.0F; // Tiempo cambio fondo (≈2.5s)
static constexpr float ANIM_DURATION_S = 80.0F / 60.0F; // Duración animación (≈1.33s)
static constexpr float CLOUDS_SPEED = -6.0F; // Velocidad nubes (pixels/s)
static constexpr float SCROLL_SPEED_PPS = 60.0F; // Velocidad de scroll (60 pixels por segundo)
// --- Objetos y punteros ---
SDL_Renderer* renderer_; // El renderizador de la ventana

View File

@@ -343,8 +343,9 @@ void Instructions::renderLines(SDL_Renderer* renderer, SDL_Texture* texture, con
void Instructions::updateBackbuffer(float delta_time) {
// Establece la ventana del backbuffer usando velocidad en pixels por segundo
// El scroll comienza desde (param.game.height + 100) y desciende a 0
// IMPORTANTE: Se redondea a entero para evitar deformaciones de textura causadas por sub-pixel rendering
float scroll_offset = elapsed_time_ * SCROLL_SPEED_PPS;
view_.y = std::max(0.0F, (param.game.height + 100.0F) - scroll_offset);
view_.y = std::round(std::max(0.0F, (param.game.height + 100.0F) - scroll_offset));
// Verifica si view_.y == 0 y gestiona el temporizador
if (view_.y == 0.0F) {