Search code examples
c++windowsfmlsprite

Flipping youtr character sprite backwards in sfml c++


I am having some small issues getting my sprite character to flip around. Basically I have a character that can walk to the right.. I am looking to flip it so that it looks like it is walking left. I haven't found a working solution at the moment so any help would be amazaing!

I am using:

SFML 2.1 C++

I have tried:

  guy.setTextureRect(sf::IntRect(guy.getGlobalBounds().width, 0, guy.getGlobalBounds.width * -1, guy.getGlobalBounds.height));

Solution

  • One way of doing it is to scale it with +/- 1 factors as follow:

    sf::Sprite sprite(texture);
    sprite.setOrigin({ sprite.getLocalBounds().width, 0 });
    sprite.setScale({ -1, 1 });