forked from jaildesigner-jailgames/jaildoctors_dilemma
Arreglos y mejoras en la clase animatedsprite
This commit is contained in:
@@ -91,6 +91,13 @@ void AnimatedSprite::animate()
|
||||
// Establece el frame actual de la animación
|
||||
void AnimatedSprite::setCurrentFrame(int num)
|
||||
{
|
||||
// Descarta valores fuera de rango
|
||||
if (num >= animation[currentAnimation].frames.size())
|
||||
{
|
||||
num = 0;
|
||||
}
|
||||
|
||||
// Cambia el valor de la variable
|
||||
animation[currentAnimation].currentFrame = num;
|
||||
|
||||
// Escoge el frame correspondiente de la animación
|
||||
@@ -154,7 +161,7 @@ bool AnimatedSprite::load(std::string filePath)
|
||||
printf("Reading file %s\n", filename.c_str());
|
||||
while (std::getline(file, line))
|
||||
{
|
||||
// Si la linea contiene el texto [enemy] se realiza el proceso de carga de un enemigo
|
||||
// Si la linea contiene el texto [animation] se realiza el proceso de carga de una animación
|
||||
if (line == "[animation]")
|
||||
{
|
||||
t_animation buffer;
|
||||
@@ -206,7 +213,7 @@ bool AnimatedSprite::load(std::string filePath)
|
||||
}
|
||||
} while (line != "[/animation]");
|
||||
|
||||
// Añade el enemigo al vector de enemigos
|
||||
// Añade la animación al vector de animaciones
|
||||
animation.push_back(buffer);
|
||||
}
|
||||
|
||||
@@ -223,14 +230,17 @@ bool AnimatedSprite::load(std::string filePath)
|
||||
{
|
||||
frames_per_row = std::stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
|
||||
else if (line.substr(0, pos) == "frame_width")
|
||||
{
|
||||
frame_width = std::stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
|
||||
else if (line.substr(0, pos) == "frame_height")
|
||||
{
|
||||
frame_height = std::stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
printf("Warning: file %s, unknown parameter \"%s\"\n", filename.c_str(), line.substr(0, pos).c_str());
|
||||
@@ -251,6 +261,12 @@ bool AnimatedSprite::load(std::string filePath)
|
||||
success = false;
|
||||
}
|
||||
|
||||
// Normaliza valores
|
||||
if (frames_per_row == 0)
|
||||
{
|
||||
frames_per_row = texture->getWidth() / frame_width;
|
||||
}
|
||||
|
||||
// Pone un valor por defecto
|
||||
setPos({0, 0, frame_width, frame_height});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user