diff --git a/data/actors/enemies/bug.ani b/data/actors/enemies/bug.ani index 05ed560..77641a9 100644 --- a/data/actors/enemies/bug.ani +++ b/data/actors/enemies/bug.ani @@ -5,6 +5,6 @@ tile_height=16 [animation] name=walk speed=8 -loop=yes +loop=0 frames=0,1,2,3,4,5 [/animation] \ No newline at end of file diff --git a/data/actors/enemies/flying_eye.ani b/data/actors/enemies/flying_eye.ani index 05ed560..77641a9 100644 --- a/data/actors/enemies/flying_eye.ani +++ b/data/actors/enemies/flying_eye.ani @@ -5,6 +5,6 @@ tile_height=16 [animation] name=walk speed=8 -loop=yes +loop=0 frames=0,1,2,3,4,5 [/animation] \ No newline at end of file diff --git a/data/actors/enemies/flying_eye_horn.ani b/data/actors/enemies/flying_eye_horn.ani index 83ca312..a2d6c20 100644 --- a/data/actors/enemies/flying_eye_horn.ani +++ b/data/actors/enemies/flying_eye_horn.ani @@ -5,6 +5,6 @@ tile_height=16 [animation] name=walk speed=6 -loop=yes +loop=0 frames=0,1,2,3,4,5 [/animation] \ No newline at end of file diff --git a/data/actors/enemies/walking_eye.ani b/data/actors/enemies/walking_eye.ani index 05ed560..77641a9 100644 --- a/data/actors/enemies/walking_eye.ani +++ b/data/actors/enemies/walking_eye.ani @@ -5,6 +5,6 @@ tile_height=16 [animation] name=walk speed=8 -loop=yes +loop=0 frames=0,1,2,3,4,5 [/animation] \ No newline at end of file diff --git a/data/player/player.ani b/data/player/player.ani index 262ddc0..1830f33 100644 --- a/data/player/player.ani +++ b/data/player/player.ani @@ -5,27 +5,27 @@ tile_height=24 [animation] name=stand speed=8 -loop=yes +loop=0 frames=0,1,2,2,1,0,0,1,2,2,1,0,0,1,2,2,1,0,0,1,2,2,1,0,0,1,2,3,4,5,4,5,5,5,6,6,7,7,0,0 [/animation] [animation] name=walk speed=4 -loop=yes +loop=0 frames=8,9,10,10,9,8,11,12,13,13,14,15 [/animation] [animation] name=jump speed=10 -loop=no +loop=-1 frames=16,17,18,17,16 [/animation] [animation] name=death speed=10 -loop=no +loop=-1 frames=24,25,26,27,28,29,30,31 [/animation] \ No newline at end of file diff --git a/source/animatedsprite.cpp b/source/animatedsprite.cpp index 09f71dd..e332533 100644 --- a/source/animatedsprite.cpp +++ b/source/animatedsprite.cpp @@ -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") { diff --git a/source/animatedsprite.h b/source/animatedsprite.h index 55d9981..81488e1 100644 --- a/source/animatedsprite.h +++ b/source/animatedsprite.h @@ -18,7 +18,7 @@ private: std::string name; // Nombre de la animacion std::vector frames; // Cada uno de los frames que componen la animación int speed; // Velocidad de la animación - bool loop; // Indica si la animación se reproduce en bucle + int loop; // Indica a que frame vuelve la animación al terminar. -1 para que no vuelva bool completed; // Indica si ha finalizado la animación int currentFrame; // Frame actual int counter; // Contador para las animaciones @@ -28,7 +28,7 @@ private: public: // Constructor - AnimatedSprite(LTexture *texture = nullptr, SDL_Renderer *renderer = nullptr, std::string file=""); + AnimatedSprite(LTexture *texture = nullptr, SDL_Renderer *renderer = nullptr, std::string file = ""); // Destructor ~AnimatedSprite(); @@ -45,8 +45,8 @@ public: // Establece la velocidad de una animación void setAnimationSpeed(std::string name, int speed); - // Establece si la animación se reproduce en bucle - void setAnimationLoop(std::string name, bool loop); + // Establece el frame al que vuelve la animación al finalizar + void setAnimationLoop(std::string name, int loop); // Establece el valor de la variable void setAnimationCompleted(std::string name, bool value);