Arreglado un bug en el cambio de paleta durante el juego

This commit is contained in:
2022-10-27 19:24:41 +02:00
parent 1934f790f7
commit c1f0f90b16
6 changed files with 46 additions and 13 deletions

View File

@@ -27,8 +27,8 @@ void Resource::loadAnimations(std::vector<std::string> list)
for (auto l : list)
{
animation_t as;
as.name = l+".ani";
as.animation = new animatedSprite_t(loadAnimationFromFile(getTexture(l+".png"), asset->get(l+".ani")));
as.name = l + ".ani";
as.animation = new animatedSprite_t(loadAnimationFromFile(getTexture(l + ".png"), asset->get(l + ".ani")));
animations.push_back(as);
}
}
@@ -52,6 +52,23 @@ void Resource::freeTextures()
textures.clear();
}
// Libera las animaciones
void Resource::freeAnimations()
{
for (auto a : animations)
{
delete a.animation;
}
animations.clear();
}
// Libera todos los recursos
void Resource::free()
{
freeTextures();
freeAnimations();
}
// Obtiene una textura
Texture *Resource::getTexture(std::string name)
{

View File

@@ -51,6 +51,12 @@ public:
// Libera las texturas
void freeTextures();
// Libera las animaciones
void freeAnimations();
// Libera todos los recursos
void free();
// Obtiene una textura
Texture *getTexture(std::string name);

View File

@@ -845,7 +845,7 @@ void Director::runLogo()
logo = new Logo(renderer, screen, resource, asset, options, section.subsection);
setSection(logo->run());
delete logo;
resource->freeTextures();
resource->free();
}
// Ejecuta la seccion de juego de la introducción
@@ -857,7 +857,7 @@ void Director::runIntro()
intro = new Intro(renderer, screen, resource, asset, options);
setSection(intro->run());
delete intro;
resource->freeTextures();
resource->free();
}
// Ejecuta la seccion de juego con el titulo y los menus
@@ -873,7 +873,7 @@ void Director::runTitle()
title = new Title(renderer, screen, resource, asset, options);
setSection(title->run());
delete title;
resource->freeTextures();
resource->free();
}
// Ejecuta la seccion de los creditos del juego
@@ -885,7 +885,7 @@ void Director::runCredits()
credits = new Credits(renderer, screen, resource, asset, options);
setSection(credits->run());
delete credits;
resource->freeTextures();
resource->free();
}
// Ejecuta la seccion de la demo, donde se ven pantallas del juego
@@ -897,7 +897,7 @@ void Director::runDemo()
demo = new Demo(renderer, screen, resource, asset, options, debug);
setSection(demo->run());
delete demo;
resource->freeTextures();
resource->free();
}
// Ejecuta la seccion de juego donde se juega
@@ -910,7 +910,7 @@ void Director::runGame()
game = new Game(renderer, screen, resource, asset, options, input, debug);
setSection(game->run());
delete game;
resource->freeTextures();
resource->free();
}
void Director::run()

View File

@@ -158,7 +158,6 @@ void Game::checkEventHandler()
case SDL_SCANCODE_F5:
switchPalette();
//reLoadTextures();
break;
default:

View File

@@ -778,11 +778,15 @@ void Room::reLoadTexture()
{
if (options->palette == p_zxspectrum)
{
texture->loadFromFile(asset->get("standard.png"), renderer);
//texture->loadFromFile(asset->get("standard.png"), renderer);
texture = resource->getTexture("standard.png");
texture->reLoad();
}
else if (options->palette == p_zxarne)
{
texture->loadFromFile(asset->get("standard_zxarne.png"), renderer);
//texture->loadFromFile(asset->get("standard_zxarne.png"), renderer);
texture = resource->getTexture("standard_zxarne.png");
texture->reLoad();
}
fillMapTexture();
@@ -815,6 +819,9 @@ void Room::reLoadPalette()
// Establece el color del borde
screen->setBorderColor(stringToColor(options->palette, borderColor));
// Recarga las texturas
reLoadTexture();
}
// Obten el tamaño del tile

View File

@@ -232,12 +232,16 @@ void Title::reLoadTextures()
// Carga la textura adecuada
if (options->palette == p_zxspectrum)
{
texture->loadFromFile(asset->get("loading_screen_color.png"), renderer);
// texture->loadFromFile(asset->get("loading_screen_color.png"), renderer);
texture = resource->getTexture("loading_screen_color.png");
}
else if (options->palette == p_zxarne)
{
texture->loadFromFile(asset->get("loading_screen_color_zxarne.png"), renderer);
// texture->loadFromFile(asset->get("loading_screen_color_zxarne.png"), renderer);
texture = resource->getTexture("loading_screen_color_zxarne.png");
}
texture->reLoad();
}
// Cambia la paleta