That's why. Now, he animates very fast, is there a solution to solve that?
If your animation is too fast just increase the delay time. Delay time depends on what kind of effect you want to give, how many sprites are you animating and so on, it's perfectly tweekable as you may wish it to be.
I am guessing that T is causing the delay I am looking for in this place.
It is indeed what causes it, notice that the getElapsedTime() function returns an sf::Time value that can be compared to other sf::Time values, take a look at this code, which is the SFML source of Time.cpp
bool operator <=(Time left, Time right)
{
return left.asMicroseconds() <= right.asMicroseconds();
}
bool operator >=(Time left, Time right)
{
return left.asMicroseconds() >= right.asMicroseconds();
}
Instead of manually converting times and ridding of the T parameter you can just compare times as needed, it has even more precision than the seconds comparison.
I just noticed that in my code I left a mistaken "asSeconds()" call. That was a mistake I overlooked since you should be comparing sf::time with another sf::time and not with a float. asSeconds() returns a float and it doesn't know how to compare itself with time, which is the reason your compiler whines.
It should look something like this:
if(clock.getElapsedTime() >= T)
My bad for overlooking this when I was refactoring your code. With that change and leaving the parameter T as I set it should work well and with no compiling errors.
Edit: As a side-note, you can perfectly use variables instead of the plain numbers, it makes your code more controllable over-time, mainly when you forget what that number meant. Not to mention that it can also may make your code work in more than one situation.
All you need to do is set the width and height variable before your loop using the texture's getSize function:
unsigned width = (texture name).getSize().x;
unsigned heigth = (texture name).getSize().y;
///further settings of the particular sprite sheet.
///Game loop and fancy stuff.
And the code can work for any sprite sheet that be organized in a horizontal way. You should always aim for making your solution broader unless you require something extremely specific you'll never use for anything else. It's always better to write one semi-universal animator than an animator for each sprite sheet you use.