forked from jaildesigner-jailgames/jaildoctors_dilemma
Trabajando en la cache de animaciones
This commit is contained in:
@@ -9,10 +9,10 @@ Resource::Resource(SDL_Renderer *renderer, Asset *asset, options_t *options)
|
||||
this->options = options;
|
||||
}
|
||||
|
||||
// Carga todos los recursos necesarios
|
||||
// Carga las texturas de una lista
|
||||
void Resource::loadTextures(std::vector<std::string> list)
|
||||
{
|
||||
std::cout << "** LOAD RESOURCES" << std::endl;
|
||||
std::cout << "** LOAD TEXTURES" << std::endl;
|
||||
for (auto l : list)
|
||||
{
|
||||
texture_t t;
|
||||
@@ -20,7 +20,21 @@ void Resource::loadTextures(std::vector<std::string> list)
|
||||
t.texture = new Texture(renderer, asset->get(t.name));
|
||||
textures.push_back(t);
|
||||
}
|
||||
std::cout << "** RESOURCES LOADED" << std::endl;
|
||||
std::cout << "** TEXTURES LOADED" << std::endl;
|
||||
}
|
||||
|
||||
// Carga las animaciones desde una lista
|
||||
void Resource::loadAnimations(std::vector<std::string> list)
|
||||
{
|
||||
std::cout << "** LOAD ANIMATIONS" << std::endl;
|
||||
for (auto l : list)
|
||||
{
|
||||
animation_t as;
|
||||
as.name = l+".ani";
|
||||
as.animation = new animatedSprite_t(loadAnimationFromFile(getTexture(l+".png"), asset->get(l+".ani")));
|
||||
animations.push_back(as);
|
||||
}
|
||||
std::cout << "** ANIMATIONS LOADED" << std::endl;
|
||||
}
|
||||
|
||||
// Recarga las texturas
|
||||
@@ -54,6 +68,22 @@ Texture *Resource::getTexture(std::string name)
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "NOT FOUND: " << name << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Obtiene una animación
|
||||
animatedSprite_t *Resource::getAnimation(std::string name)
|
||||
{
|
||||
for (auto animation : animations)
|
||||
{
|
||||
if (animation.name.find(name) != std::string::npos)
|
||||
{
|
||||
std::cout << "CACHE: " << name << std::endl;
|
||||
return animation.animation;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "NOT FOUND: " << name << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
Reference in New Issue
Block a user