SFML community forums

Help => General => Topic started by: Chunker120 on May 12, 2013, 04:44:07 pm

Title: How to flip sprite horizontal?
Post by: Chunker120 on May 12, 2013, 04:44:07 pm
I have an animation in a top-down perspective, but I want the sprite to get flipped horizontal if the player faces east. The sprite class doesn't by default have any methods that would help me achieve that, so how would I go around flipping a sprite horizontally?
Title: Re: How to flip sprite horizontal?
Post by: Grimshaw on May 12, 2013, 05:05:24 pm
sprite.scale(-1,1);

:)
Title: Re: How to flip sprite horizontal?
Post by: lrx on May 12, 2013, 05:05:52 pm
probably rotating (http://www.sfml-dev.org/documentation/2.0/classsf_1_1Transformable.php#af8a5ffddc0d93f238fee3bf8efe1ebda) sprite would be easiest

edit: nvm scaling is even easier then rotating :P
Title: Re: How to flip sprite horizontal?
Post by: Nexus on May 12, 2013, 05:13:59 pm
edit: nvm scaling is even easier then rotating :P
The operations are not equivalent. Rotating by 180° won't give you the mirror image (the sprite looks upside down). The alternative to scaling is to set the texture rect using a negative width.

By the way, this has been asked many times, please use the forum search before posting.