forked from jaildesigner-jailgames/jaildoctors_dilemma
Trabajando en la recarga de texturas
This commit is contained in:
@@ -21,13 +21,20 @@ void Resource::loadTextures(std::vector<std::string> list)
|
||||
}
|
||||
}
|
||||
|
||||
// Libera los recursos
|
||||
void Resource::freeTextures()
|
||||
// Recarga las texturas
|
||||
void Resource::reLoadTextures()
|
||||
{
|
||||
for (auto texture : textures)
|
||||
{
|
||||
texture.texture->reLoad();
|
||||
}
|
||||
}
|
||||
|
||||
// Libera las texturas
|
||||
void Resource::freeTextures()
|
||||
{
|
||||
// Libera las texturas
|
||||
for (auto texture : textures)
|
||||
{
|
||||
texture.texture->unload();
|
||||
delete texture.texture;
|
||||
}
|
||||
textures.clear();
|
||||
@@ -36,18 +43,15 @@ void Resource::freeTextures()
|
||||
// Obtiene una textura
|
||||
Texture *Resource::getTexture(std::string name)
|
||||
{
|
||||
//std::cout << "BUSCANDO TEXTURA" << std::endl;
|
||||
for (auto texture : textures)
|
||||
{
|
||||
//std::cout << "COMPROBANDO: " << texture.name << " - " << name << std::endl;
|
||||
|
||||
if (texture.name.find(name) != std::string::npos)
|
||||
{
|
||||
std::cout << "CACHE: " << name << std::endl;
|
||||
return texture.texture;
|
||||
}
|
||||
}
|
||||
std::cout << "NO ENCONTRADA: " << name << std::endl;
|
||||
|
||||
std::cout << "NO ENCONTRADA: " << name << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
@@ -34,7 +34,10 @@ public:
|
||||
// Carga todos los recursos necesarios
|
||||
void loadTextures(std::vector<std::string> textureList);
|
||||
|
||||
// Libera los recursos
|
||||
// Recarga las texturas
|
||||
void reLoadTextures();
|
||||
|
||||
// Libera las texturas
|
||||
void freeTextures();
|
||||
|
||||
// Obtiene una textura
|
||||
|
||||
@@ -9,7 +9,7 @@ Director::Director(std::string path)
|
||||
section.name = SECTION_PROG_LOGO;
|
||||
section.subsection = SUBSECTION_LOGO_TO_INTRO;
|
||||
|
||||
section.name = SECTION_PROG_GAME;
|
||||
section.name = SECTION_PROG_TITLE;
|
||||
|
||||
// Crea el objeto que controla los ficheros de recursos
|
||||
asset = new Asset(path.substr(0, path.find_last_of("\\/")));
|
||||
|
||||
@@ -97,8 +97,46 @@ void Intro::checkEventHandler()
|
||||
// Cualquier tecla pulsada
|
||||
if ((eventHandler->type == SDL_KEYDOWN) || (eventHandler->type == SDL_JOYBUTTONDOWN))
|
||||
{
|
||||
switch (eventHandler->key.keysym.scancode)
|
||||
{
|
||||
case SDL_SCANCODE_B:
|
||||
screen->switchBorder();
|
||||
resource->reLoadTextures();
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_F:
|
||||
screen->switchVideoMode();
|
||||
resource->reLoadTextures();
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_F1:
|
||||
screen->setWindowSize(1);
|
||||
resource->reLoadTextures();
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_F2:
|
||||
screen->setWindowSize(2);
|
||||
resource->reLoadTextures();
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_F3:
|
||||
screen->setWindowSize(3);
|
||||
resource->reLoadTextures();
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_F4:
|
||||
screen->setWindowSize(4);
|
||||
resource->reLoadTextures();
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_F5:
|
||||
switchPalette();
|
||||
break;
|
||||
|
||||
default:
|
||||
section.name = SECTION_PROG_TITLE;
|
||||
section.subsection = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -248,3 +286,20 @@ section_t Intro::run()
|
||||
|
||||
return section;
|
||||
}
|
||||
|
||||
// Cambia la paleta
|
||||
void Intro::switchPalette()
|
||||
{
|
||||
if (options->palette == p_zxspectrum)
|
||||
{
|
||||
options->palette = p_zxarne;
|
||||
loadingScreenTexture1 = resource->getTexture("loading_screen_bn_zxarne.png");
|
||||
loadingScreenTexture2 = resource->getTexture("loading_screen_color_zxarne.png");
|
||||
}
|
||||
else
|
||||
{
|
||||
options->palette = p_zxspectrum;
|
||||
loadingScreenTexture1 = resource->getTexture("loading_screen_bn.png");
|
||||
loadingScreenTexture2 = resource->getTexture("loading_screen_color.png");
|
||||
}
|
||||
}
|
||||
@@ -64,6 +64,9 @@ private:
|
||||
// Dibuja la pantalla de carga
|
||||
void renderLoad();
|
||||
|
||||
// Cambia la paleta
|
||||
void switchPalette();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Intro(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options);
|
||||
|
||||
@@ -783,8 +783,9 @@ void Room::reLoadTexture()
|
||||
{
|
||||
texture->loadFromFile(asset->get("standard_zxarne.png"), renderer);
|
||||
}
|
||||
// texture->reLoad();
|
||||
|
||||
fillMapTexture();
|
||||
|
||||
for (auto enemy : enemies)
|
||||
{
|
||||
enemy->reLoadTexture();
|
||||
|
||||
@@ -107,7 +107,7 @@ void Title::checkEventHandler()
|
||||
|
||||
case SDL_SCANCODE_F5:
|
||||
switchPalette();
|
||||
reLoadTextures();
|
||||
// reLoadTextures();
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -247,12 +247,19 @@ void Title::switchPalette()
|
||||
if (options->palette == p_zxspectrum)
|
||||
{
|
||||
options->palette = p_zxarne;
|
||||
texture = resource->getTexture("loading_screen_color_zxarne.png");
|
||||
sprite->setTexture(texture);
|
||||
}
|
||||
else
|
||||
{
|
||||
options->palette = p_zxspectrum;
|
||||
texture = resource->getTexture("loading_screen_color.png");
|
||||
sprite->setTexture(texture);
|
||||
}
|
||||
|
||||
// resource->reLoadTextures();
|
||||
// reLoadTextures();
|
||||
|
||||
// Cambia el color del borde
|
||||
screen->setBorderColor(stringToColor(options->palette, "bright_blue"));
|
||||
}
|
||||
Reference in New Issue
Block a user