forked from jaildesigner-jailgames/jaildoctors_dilemma
Optimizaciones de código
This commit is contained in:
@@ -49,9 +49,12 @@ Credits::Credits(SDL_Renderer *renderer, Screen *screen, Asset *asset)
|
||||
texts.push_back("");
|
||||
|
||||
// Crea la textura para el texto que se escribe en pantalla
|
||||
textTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
|
||||
if (textTexture == NULL)
|
||||
printf("Error: textTexture could not be created!\nSDL Error: %s\n", SDL_GetError());
|
||||
textTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
|
||||
if (textTexture == nullptr)
|
||||
{
|
||||
printf("Error: textTexture could not be created!\nSDL Error: %s\n", SDL_GetError());
|
||||
}
|
||||
SDL_SetTextureBlendMode(textTexture, SDL_BLENDMODE_BLEND);
|
||||
|
||||
// Escribe el texto en la textura
|
||||
fillTexture();
|
||||
@@ -101,18 +104,21 @@ void Credits::checkEventHandler()
|
||||
// Escribe el texto en la textura
|
||||
void Credits::fillTexture()
|
||||
{
|
||||
SDL_SetRenderTarget(renderer, textTexture);
|
||||
SDL_SetTextureBlendMode(textTexture, SDL_BLENDMODE_BLEND);
|
||||
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0x00);
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_SetRenderTarget(renderer, textTexture);
|
||||
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0x00);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
// Escribe el texto en la textura
|
||||
for (int i = 0; i < texts.size(); ++i)
|
||||
// Escribe el texto en la textura
|
||||
const int size = text->getCharacterSize();
|
||||
int i = 0;
|
||||
|
||||
for (auto t:texts)
|
||||
{
|
||||
text->write(0, i * 8, texts[i]);
|
||||
text->write(0, i * size, t);
|
||||
++i;
|
||||
}
|
||||
|
||||
SDL_SetRenderTarget(renderer, nullptr);
|
||||
SDL_SetRenderTarget(renderer, nullptr);
|
||||
}
|
||||
|
||||
// Actualiza las variables
|
||||
@@ -128,7 +134,7 @@ void Credits::update()
|
||||
checkEventHandler();
|
||||
|
||||
// Incrementa el contador
|
||||
counter++;
|
||||
++counter;
|
||||
|
||||
// Comprueba si ha terminado la sección
|
||||
if (counter > 1000)
|
||||
@@ -147,11 +153,10 @@ void Credits::render()
|
||||
// Limpia la pantalla
|
||||
screen->clean();
|
||||
|
||||
SDL_Rect rect = {0, 0, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT};
|
||||
|
||||
// Dibuja la textura con el mapa en pantalla
|
||||
SDL_RenderCopy(renderer, textTexture, &rect, NULL);
|
||||
SDL_Rect rect = {0, 0, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT};
|
||||
|
||||
// Dibuja la textura con el mapa en pantalla
|
||||
SDL_RenderCopy(renderer, textTexture, &rect, nullptr);
|
||||
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
screen->blit();
|
||||
|
||||
Reference in New Issue
Block a user