Modificado el loop de las animaciones
This commit is contained in:
@@ -45,13 +45,18 @@ void AnimatedSprite::animate()
|
||||
animation[currentAnimation].currentFrame = animation[currentAnimation].counter / animation[currentAnimation].speed;
|
||||
|
||||
// Si alcanza el final de la animación, reinicia el contador de la animación
|
||||
// en función de la variable loop
|
||||
// en función de la variable loop y coloca el nuevo frame
|
||||
if (animation[currentAnimation].currentFrame >= animation[currentAnimation].frames.size())
|
||||
{
|
||||
if (animation[currentAnimation].loop)
|
||||
animation[currentAnimation].counter = 0;
|
||||
else
|
||||
if (animation[currentAnimation].loop == -1)
|
||||
{ // Si no hay loop, deja el último frame
|
||||
animation[currentAnimation].currentFrame = animation[currentAnimation].frames.size();
|
||||
}
|
||||
else
|
||||
{ // Si hay loop, vuelve al frame indicado
|
||||
animation[currentAnimation].counter = 0;
|
||||
animation[currentAnimation].currentFrame = animation[currentAnimation].loop;
|
||||
}
|
||||
}
|
||||
// En caso contrario
|
||||
else
|
||||
@@ -84,7 +89,7 @@ void AnimatedSprite::setAnimationSpeed(std::string name, int speed)
|
||||
}
|
||||
|
||||
// Establece si la animación se reproduce en bucle
|
||||
void AnimatedSprite::setAnimationLoop(std::string name, bool loop)
|
||||
void AnimatedSprite::setAnimationLoop(std::string name, int loop)
|
||||
{
|
||||
animation[getIndex(name)].loop = loop;
|
||||
}
|
||||
@@ -155,14 +160,7 @@ bool AnimatedSprite::load(std::string filePath)
|
||||
}
|
||||
else if (line.substr(0, pos) == "loop")
|
||||
{
|
||||
if (line.substr(pos + 1, line.length()) == "yes" || line.substr(pos + 1, line.length()) == "true")
|
||||
{
|
||||
buffer.loop = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.loop = false;
|
||||
}
|
||||
buffer.loop = std::stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
else if (line.substr(0, pos) == "frames")
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user