Hey guys!
I found a forum post explaining how to flip a sprite in SFML 2.0, but it doesn't seem to be working well in my game and I can't find where I went wrong. The problem is, it only flips the sprite once and it won't ever flip it back to original. Here is the code:
// The flip function works well
void Flip(sf::Sprite& sprite)
{
sprite.setTextureRect(
sf::IntRect(
sprite.getLocalBounds().width,
0,
-sprite.getLocalBounds().width,
sprite.getLocalBounds().height
)
);
}
while (window.isOpen())
{
vector.x = 0;
vector.y = 0;
// Input
while (window.pollEvent(event))
{
// ...
}
// Same thing with the right key, you get the idea
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
{
vector.x -= 7;
if (direction != LEFT)
{
direction = LEFT;
Flip(sprite);
}
}
// ...
sprite.setTexture(
spriteAnimTextures[spriteAnim.GetCurrentFrame()]
);
}
Now, as I said, after the first flip to the right, it stops working. What might be the error here?