SFML community forums

Help => Graphics => Topic started by: ayzed on April 12, 2012, 04:52:06 am

Title: Sfml 2.0 Flipping a sprite
Post by: ayzed on April 12, 2012, 04:52:06 am
Is there a way to flip a sprite as easy as FlipX() in sfml 1.6 ???
Title: Re: Sfml 2.0 Flipping a sprite
Post by: ChonDee on April 12, 2012, 07:55:25 am
Sprite.Scale(-1.f,1.f); is the simplest way as far as I know
Title: Re: Sfml 2.0 Flipping a sprite
Post by: ayzed on April 12, 2012, 03:46:00 pm
Using scale change the position too, I don't want that,how can i solve it?
Title: Re: Sfml 2.0 Flipping a sprite
Post by: Laurent on April 12, 2012, 03:48:45 pm
Quote
Using scale change the position too, I don't want that,how can i solve it?
You can set the origin of the sprite to its center (half-size).
Title: Re: Sfml 2.0 Flipping a sprite
Post by: ayzed on April 12, 2012, 04:44:21 pm
it works :D
somthing else, why animations from sprites are buggy and sometimes the images disappear?
Title: Re: Sfml 2.0 Flipping a sprite
Post by: Laurent on April 12, 2012, 04:57:57 pm
Quote
somthing else, why animations from sprites are buggy and sometimes the images disappear?
Because there are errors in your code?
Title: Re: Sfml 2.0 Flipping a sprite
Post by: ayzed on April 12, 2012, 05:16:28 pm
nvm, thank you for you fast answers :D :D :D
Title: Re: Sfml 2.0 Flipping a sprite
Post by: arjungmenon on January 30, 2013, 11:12:08 am
Hey Laurent,

I found the flip function in SFML 1.6 quite handy; and while this solution works for 2.0, it seems a bit less elegant than the previous method.

Is there any chance that you'd be adding back the flip methods to SFML 2.0 ?
Title: Re: Sfml 2.0 Flipping a sprite
Post by: Laurent on January 30, 2013, 11:45:38 am
Nop. Note that there's a better solution: using a textureRect with negative width/height (this solution maps exactly to what the Flip functions did).

// flip X
sprite.setTextureRect(sf::IntRect(width, 0, -width, height));

If you really miss the Flip functions, you can write yours as free functions, using the implementation above.
Title: Re: Sfml 2.0 Flipping a sprite
Post by: Battleapple on December 26, 2013, 09:21:26 pm
Nop. Note that there's a better solution: using a textureRect with negative width/height (this solution maps exactly to what the Flip functions did).

// flip X
sprite.setTextureRect(sf::IntRect(width, 0, -width, height));

If you really miss the Flip functions, you can write yours as free functions, using the implementation above.

When I use this I can only flip it once?
Title: Re: Sfml 2.0 Flipping a sprite
Post by: G. on December 26, 2013, 09:35:48 pm
What do you mean once?
// flip X
sprite.setTextureRect(sf::IntRect(width, 0, -width, height));

// unflip X
sprite.setTextureRect(sf::IntRect(0, 0, width, height));
Title: Re: Sfml 2.0 Flipping a sprite
Post by: Battleapple on December 26, 2013, 09:38:56 pm
What do you mean once?
// flip X
sprite.setTextureRect(sf::IntRect(width, 0, -width, height));

// unflip X
sprite.setTextureRect(sf::IntRect(0, 0, width, height));

I did not find the correct values for unflipping it.So thank you for helping me  :)
Title: Re: Sfml 2.0 Flipping a sprite
Post by: G. on December 26, 2013, 11:17:07 pm
The correct values are the values you use to draw the sprite normally, simply. :p