0
\$\begingroup\$

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));
\$\endgroup\$
2
  • \$\begingroup\$ Try setting its X scale to -1 \$\endgroup\$ Oct 15, 2014 at 22:48
  • \$\begingroup\$ I tried that by doing guy.setScale(-1.0f, 1) and it makes the sprite disapear \$\endgroup\$
    – Bryce
    Oct 16, 2014 at 0:49

1 Answer 1

1
\$\begingroup\$

The sf::IntRect that you will use will be the same for both directions. What will need to be changed is the scale of the sf::Sprite variable.

You will simply need to do something similar to this:

// Assumes that the image side is 24x32 and it is the first frame of the sprite
sf::IntRect test(0,0,24,32);
playerSprite.setTextureRect(test);
if( walkingleft ){
    playerSprite.setScale(-1.0f,1.0f);  //flip the sprite
}
// draw sprite afterwards...

Is the code you tried on your question the exact code you tried out, because it looks incorrect?

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

They are suppose to be functions.

\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .