Optimitzat el renderitzat dels credits
This commit is contained in:
@@ -31,6 +31,7 @@ constexpr const char TEXT_COPYRIGHT[] = "@2020,2025 JailDesigner";
|
|||||||
Credits::Credits()
|
Credits::Credits()
|
||||||
: balloon_manager_(std::make_unique<BalloonManager>()),
|
: balloon_manager_(std::make_unique<BalloonManager>()),
|
||||||
text_texture_(SDL_CreateTexture(Screen::get()->getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)),
|
text_texture_(SDL_CreateTexture(Screen::get()->getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)),
|
||||||
|
canvas_(SDL_CreateTexture(Screen::get()->getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)),
|
||||||
tiled_bg_(std::make_unique<TiledBG>(param.game.game_area.rect, TiledBGMode::DIAGONAL)),
|
tiled_bg_(std::make_unique<TiledBG>(param.game.game_area.rect, TiledBGMode::DIAGONAL)),
|
||||||
fade_in_(std::make_unique<Fade>()),
|
fade_in_(std::make_unique<Fade>()),
|
||||||
fade_out_(std::make_unique<Fade>())
|
fade_out_(std::make_unique<Fade>())
|
||||||
@@ -62,6 +63,7 @@ Credits::Credits()
|
|||||||
Credits::~Credits()
|
Credits::~Credits()
|
||||||
{
|
{
|
||||||
SDL_DestroyTexture(text_texture_);
|
SDL_DestroyTexture(text_texture_);
|
||||||
|
SDL_DestroyTexture(canvas_);
|
||||||
resetVolume();
|
resetVolume();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,6 +103,8 @@ void Credits::update()
|
|||||||
}
|
}
|
||||||
Screen::get()->update();
|
Screen::get()->update();
|
||||||
globalInputs::update();
|
globalInputs::update();
|
||||||
|
|
||||||
|
fillCanvas();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,39 +114,8 @@ void Credits::render()
|
|||||||
// Prepara para empezar a dibujar en la textura de juego
|
// Prepara para empezar a dibujar en la textura de juego
|
||||||
Screen::get()->start();
|
Screen::get()->start();
|
||||||
|
|
||||||
// Limpia la pantalla
|
// Copia la textura con la zona de juego a la pantalla
|
||||||
Screen::get()->clean();
|
SDL_RenderCopy(Screen::get()->getRenderer(), canvas_, nullptr, nullptr);
|
||||||
|
|
||||||
// Dibuja el fondo, los globos y los jugadores
|
|
||||||
tiled_bg_->render();
|
|
||||||
balloon_manager_->render();
|
|
||||||
for (auto const &player : players_)
|
|
||||||
{
|
|
||||||
player->render();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dibuja los titulos de credito
|
|
||||||
SDL_RenderCopy(Screen::get()->getRenderer(), text_texture_, &credits_rect_src_, &credits_rect_dst_);
|
|
||||||
|
|
||||||
// Dibuja el mini_logo
|
|
||||||
SDL_RenderCopy(Screen::get()->getRenderer(), text_texture_, &mini_logo_rect_src_, &mini_logo_rect_dst_);
|
|
||||||
|
|
||||||
// Dibuja los rectangulos negros
|
|
||||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 255);
|
|
||||||
SDL_RenderFillRect(Screen::get()->getRenderer(), &top_black_rect_);
|
|
||||||
SDL_RenderFillRect(Screen::get()->getRenderer(), &bottom_black_rect_);
|
|
||||||
SDL_RenderFillRect(Screen::get()->getRenderer(), &left_black_rect_);
|
|
||||||
SDL_RenderFillRect(Screen::get()->getRenderer(), &right_black_rect_);
|
|
||||||
|
|
||||||
// Si el mini_logo está en su destino, lo dibuja encima de lo anterior
|
|
||||||
if (mini_logo_on_position_)
|
|
||||||
{
|
|
||||||
SDL_RenderCopy(Screen::get()->getRenderer(), text_texture_, &mini_logo_rect_src_, &mini_logo_rect_dst_);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dibuja el fade sobre el resto de elementos
|
|
||||||
fade_in_->render();
|
|
||||||
fade_out_->render();
|
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
Screen::get()->blit();
|
Screen::get()->blit();
|
||||||
@@ -280,6 +253,48 @@ void Credits::fillTextTexture()
|
|||||||
mini_logo_final_pos_ = param.game.game_area.center_y - mini_logo_rect_src_.h / 2;
|
mini_logo_final_pos_ = param.game.game_area.center_y - mini_logo_rect_src_.h / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Dibuja todos los sprites en la textura
|
||||||
|
void Credits::fillCanvas()
|
||||||
|
{
|
||||||
|
// Cambia el destino del renderizador
|
||||||
|
auto temp = SDL_GetRenderTarget(Screen::get()->getRenderer());
|
||||||
|
SDL_SetRenderTarget(Screen::get()->getRenderer(), canvas_);
|
||||||
|
|
||||||
|
// Dibuja el fondo, los globos y los jugadores
|
||||||
|
tiled_bg_->render();
|
||||||
|
balloon_manager_->render();
|
||||||
|
for (auto const &player : players_)
|
||||||
|
{
|
||||||
|
player->render();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dibuja los titulos de credito
|
||||||
|
SDL_RenderCopy(Screen::get()->getRenderer(), text_texture_, &credits_rect_src_, &credits_rect_dst_);
|
||||||
|
|
||||||
|
// Dibuja el mini_logo
|
||||||
|
SDL_RenderCopy(Screen::get()->getRenderer(), text_texture_, &mini_logo_rect_src_, &mini_logo_rect_dst_);
|
||||||
|
|
||||||
|
// Dibuja los rectangulos negros
|
||||||
|
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 255);
|
||||||
|
SDL_RenderFillRect(Screen::get()->getRenderer(), &top_black_rect_);
|
||||||
|
SDL_RenderFillRect(Screen::get()->getRenderer(), &bottom_black_rect_);
|
||||||
|
SDL_RenderFillRect(Screen::get()->getRenderer(), &left_black_rect_);
|
||||||
|
SDL_RenderFillRect(Screen::get()->getRenderer(), &right_black_rect_);
|
||||||
|
|
||||||
|
// Si el mini_logo está en su destino, lo dibuja encima de lo anterior
|
||||||
|
if (mini_logo_on_position_)
|
||||||
|
{
|
||||||
|
SDL_RenderCopy(Screen::get()->getRenderer(), text_texture_, &mini_logo_rect_src_, &mini_logo_rect_dst_);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dibuja el fade sobre el resto de elementos
|
||||||
|
fade_in_->render();
|
||||||
|
fade_out_->render();
|
||||||
|
|
||||||
|
// Deja el renderizador apuntando donde estaba
|
||||||
|
SDL_SetRenderTarget(Screen::get()->getRenderer(), temp);
|
||||||
|
}
|
||||||
|
|
||||||
// Actualiza el destino de los rectangulos de las texturas
|
// Actualiza el destino de los rectangulos de las texturas
|
||||||
void Credits::updateTextureDstRects()
|
void Credits::updateTextureDstRects()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ private:
|
|||||||
// Objetos
|
// Objetos
|
||||||
std::unique_ptr<BalloonManager> balloon_manager_; // Objeto para gestionar los globos
|
std::unique_ptr<BalloonManager> balloon_manager_; // Objeto para gestionar los globos
|
||||||
SDL_Texture *text_texture_; // Textura con el texto
|
SDL_Texture *text_texture_; // Textura con el texto
|
||||||
|
SDL_Texture *canvas_; // Textura donde dibujarlo todo
|
||||||
std::unique_ptr<TiledBG> tiled_bg_; // Objeto para dibujar el mosaico animado de fondo
|
std::unique_ptr<TiledBG> tiled_bg_; // Objeto para dibujar el mosaico animado de fondo
|
||||||
std::unique_ptr<Fade> fade_in_; // Objeto para realizar el fundido de entrada
|
std::unique_ptr<Fade> fade_in_; // Objeto para realizar el fundido de entrada
|
||||||
std::unique_ptr<Fade> fade_out_; // Objeto para realizar el fundido de salida
|
std::unique_ptr<Fade> fade_out_; // Objeto para realizar el fundido de salida
|
||||||
@@ -66,6 +67,9 @@ private:
|
|||||||
// Crea la textura con el texto
|
// Crea la textura con el texto
|
||||||
void fillTextTexture();
|
void fillTextTexture();
|
||||||
|
|
||||||
|
// Dibuja todos los sprites en la textura
|
||||||
|
void fillCanvas();
|
||||||
|
|
||||||
// Actualiza el destino de los rectangulos de las texturas
|
// Actualiza el destino de los rectangulos de las texturas
|
||||||
void updateTextureDstRects();
|
void updateTextureDstRects();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user