fix: les notificacions ja no embruten la pantalla de càrrega

This commit is contained in:
2025-02-28 14:00:59 +01:00
parent 7a685c0cc8
commit 5bb2b5e7c4
2 changed files with 62 additions and 13 deletions

View File

@@ -14,6 +14,7 @@
#include "sprite.h" // for Sprite
#include "texture.h" // for Texture
#include "utils.h" // for Color, stringToColor, Palette
#include <iostream>
// Constructor
LoadingScreen::LoadingScreen()
@@ -40,6 +41,16 @@ LoadingScreen::LoadingScreen()
loading_sound2_ = resource_->getMusic("loading_sound2.ogg");
loading_sound3_ = resource_->getMusic("loading_sound3.ogg");
texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, options.game.width, options.game.height);
if (texture_ == nullptr)
{
if (options.console)
{
std::cout << "LoadingScreen::texture_ could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
}
}
clearTexture();
// Inicializa variables
options.section.section = Section::LOADING_SCREEN;
options.section.subsection = Subsection::NONE;
@@ -71,6 +82,7 @@ LoadingScreen::LoadingScreen()
LoadingScreen::~LoadingScreen()
{
JA_StopMusic();
SDL_DestroyTexture(texture_);
}
// Comprueba el manejador de eventos
@@ -193,6 +205,7 @@ void LoadingScreen::update()
checkInput();
updateCounter();
updateLoad();
fillTexture();
screen_->update();
}
}
@@ -212,8 +225,8 @@ void LoadingScreen::render()
// Prepara para empezar a dibujar en la textura de juego
screen_->start();
// Dibuja la pantalla de carga
renderLoad();
// Copila la textura a la pantalla
SDL_RenderCopy(renderer_, texture_, nullptr, nullptr);
// Vuelca el contenido del renderizador en pantalla
screen_->render();
@@ -278,4 +291,33 @@ void LoadingScreen::recreateLoadingScreen()
// Vuelca el contenido del renderizador en pantalla
screen_->render();
}
// Dibuja sobre la textura
void LoadingScreen::fillTexture()
{
// Empieza a dibujar en la textura
auto temp = SDL_GetRenderTarget(renderer_);
SDL_SetRenderTarget(renderer_, texture_);
// Dibuja la pantalla de carga
renderLoad();
// Deja el renderizador como estaba
SDL_SetRenderTarget(renderer_, temp);
}
// Limpia la textura
void LoadingScreen::clearTexture()
{
// Empieza a dibujar en la textura
auto temp = SDL_GetRenderTarget(renderer_);
SDL_SetRenderTarget(renderer_, texture_);
// Limpia
SDL_SetRenderDrawColor(renderer_, 0x00, 0x00, 0x00, 0xFF);
SDL_RenderClear(renderer_);
// Deja el renderizador como estaba
SDL_SetRenderTarget(renderer_, temp);
}