forked from jaildesigner-jailgames/jaildoctors_dilemma
Empezando a trabajar en la precarga de recursos para el juego
This commit is contained in:
@@ -7,10 +7,17 @@ AnimatedSprite::AnimatedSprite(Texture *texture, SDL_Renderer *renderer, std::st
|
||||
setTexture(texture);
|
||||
setRenderer(renderer);
|
||||
|
||||
animatedSprite_t as;
|
||||
// Carga las animaciones
|
||||
if (file != "")
|
||||
{
|
||||
loadFromFile(file);
|
||||
as = loadFromFile(file);
|
||||
|
||||
// Copia los datos de las animaciones
|
||||
for (auto animation : as.animations)
|
||||
{
|
||||
this->animation.push_back(animation);
|
||||
}
|
||||
}
|
||||
|
||||
else if (buffer)
|
||||
@@ -22,6 +29,23 @@ AnimatedSprite::AnimatedSprite(Texture *texture, SDL_Renderer *renderer, std::st
|
||||
currentAnimation = 0;
|
||||
}
|
||||
|
||||
// Constructor
|
||||
AnimatedSprite::AnimatedSprite(animatedSprite_t as)
|
||||
{
|
||||
// Copia los punteros
|
||||
setTexture(as.texture);
|
||||
setRenderer(as.renderer);
|
||||
|
||||
// Inicializa variables
|
||||
currentAnimation = 0;
|
||||
|
||||
// Copia los datos de las animaciones
|
||||
for (auto animation : as.animations)
|
||||
{
|
||||
this->animation.push_back(animation);
|
||||
}
|
||||
}
|
||||
|
||||
// Destructor
|
||||
AnimatedSprite::~AnimatedSprite()
|
||||
{
|
||||
@@ -172,16 +196,15 @@ SDL_Rect AnimatedSprite::getAnimationClip(int indexA, Uint8 indexF)
|
||||
}
|
||||
|
||||
// Carga la animación desde un fichero
|
||||
bool AnimatedSprite::loadFromFile(std::string filePath)
|
||||
animatedSprite_t AnimatedSprite::loadFromFile(std::string filePath)
|
||||
{
|
||||
// Inicializa variables
|
||||
animatedSprite_t as;
|
||||
int framesPerRow = 0;
|
||||
int frameWidth = 0;
|
||||
int frameHeight = 0;
|
||||
int maxTiles = 0;
|
||||
|
||||
// Indicador de éxito en la carga
|
||||
bool success = true;
|
||||
|
||||
const std::string filename = filePath.substr(filePath.find_last_of("\\/") + 1);
|
||||
std::ifstream file(filePath);
|
||||
std::string line;
|
||||
@@ -245,13 +268,13 @@ bool AnimatedSprite::loadFromFile(std::string filePath)
|
||||
else
|
||||
{
|
||||
printf("Warning: file %s, unknown parameter \"%s\"\n", filename.c_str(), line.substr(0, pos).c_str());
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
} while (line != "[/animation]");
|
||||
|
||||
// Añade la animación al vector de animaciones
|
||||
animation.push_back(buffer);
|
||||
as.animations.push_back(buffer);
|
||||
// animation.push_back(buffer);
|
||||
}
|
||||
|
||||
// En caso contrario se parsea el fichero para buscar las variables y los valores
|
||||
@@ -281,7 +304,6 @@ bool AnimatedSprite::loadFromFile(std::string filePath)
|
||||
else
|
||||
{
|
||||
printf("Warning: file %s, unknown parameter \"%s\"\n", filename.c_str(), line.substr(0, pos).c_str());
|
||||
success = false;
|
||||
}
|
||||
|
||||
// Normaliza valores
|
||||
@@ -307,13 +329,16 @@ bool AnimatedSprite::loadFromFile(std::string filePath)
|
||||
else
|
||||
{
|
||||
printf("Warning: Unable to open %s file\n", filename.c_str());
|
||||
success = false;
|
||||
}
|
||||
|
||||
// Pone un valor por defecto
|
||||
setRect({0, 0, frameWidth, frameHeight});
|
||||
|
||||
return success;
|
||||
// Añade los punteros
|
||||
as.texture = texture;
|
||||
as.renderer = renderer;
|
||||
|
||||
return as;
|
||||
}
|
||||
|
||||
// Carga la animación desde un vector
|
||||
|
||||
Reference in New Issue
Block a user