Hello, i'm looking for a solution to my problem, i can't figure out how to fix it.
So, i coded this simple animation class:
#pragma once
#include <SFML/Graphics.hpp>
class Animator
{
private:
int framesPassed = 0;
sf::Sprite* EntitySprite;
sf::IntRect EntityRect;
sf::Texture EntityTexture;
sf::Clock clock;
public:
Animator(sf::Sprite& sprite, sf::IntRect entityRect, std::string pathToSpriteSheet) {
EntityTexture.loadFromFile(pathToSpriteSheet);
EntitySprite = &sprite;
EntityRect = entityRect;
EntitySprite->setTexture(EntityTexture);
EntitySprite->setTextureRect(EntityRect);
}
void applyAnimation(int intRectLeftAdd, float animationSpeed, int intRectResetAt, int intRectResetTo) {
EntitySprite->setTextureRect(EntityRect);
if (clock.getElapsedTime().asSeconds() > animationSpeed) {
EntityRect.left += intRectLeftAdd;
if (EntityRect.left >= intRectResetAt) {
EntityRect.left = intRectResetTo;
}
EntitySprite->setTextureRect(EntityRect);
framesPassed++;
clock.restart();
}
}
};
and its working correctly for repeating animations like walking, idle. But now i wan't to do a dead animation, but it cannot repeat, so i was trying to add variables like frames, but i dont know how to implement it, i know that i can use something like:
if(this.frames == framse) return;
but since its running every frame its resseting and not working.
So I don't know how to play the animation once (dead sprite has 4 frames) and after it reaches the end (last frame), I want to stop the animation, like freeze it on the last frame.