SFML community forums

General => Feature requests => Topic started by: masskiller on November 09, 2012, 11:58:45 pm

Title: Inverting a texture/sprite
Post by: masskiller on November 09, 2012, 11:58:45 pm
I was working on my sprite sheet and found something interesting that could be useful for SFML that I think it's not yet implemented, correct me if it is, or if there is another way to this via sf::Sprite.

Let's say I have a an image and I want to flip it horizontally or vertically, you can easily do it with openGL by changing the way you map the texture to the quad, but if I did that I would lose the high level awesomeness that is an sf::sprite.

This would help those who have a sprite that is visually rotated to one side (i.e. a person looking to the side, etc) and want to make the sprite "look" the other way (or being upside down) using the same sprite.

I know well that you can do the exact thing I am saying with photoshop, SAI, Gimp or any other software for digital work, but when animating something it would just be wondrous to just flip your sprite instead of making another row in your sprite sheet. It can also become a very tedious thing to do when your sprite sheet for animations is big and you can't flip (not my current case hopefully). Not to say that it will reduce the size of the image for the sprite sheet.

I was thinking in a sprite function like:

 
sf::sprite spr;  
...

spr.HorizontalFlip(); ///It would flip the sprite to the opposite direction horizontally.
spr.VerticalFlip(); ///Same but in a vertical fashion.
 

Which would work with the texture associated with the sprite being worked with.
There could also be the same functions for sf::texture in order to flip the texture whatever way you want before the setTexture() call.

I'll attach two images of my sprites to show exactly what I mean.

[attachment deleted by admin]
Title: Re: Inverting a texture/sprite
Post by: FRex on November 10, 2012, 12:28:28 am
scaling by -1,1 ...
Title: Re: Inverting a texture/sprite
Post by: Laurent on November 10, 2012, 09:24:56 am
Quote
you can easily do it with openGL by changing the way you map the texture to the quad
... that setTextureRect can control (don't be afraid to use negative width/height).

Quote
scaling by -1,1 ...
It is not the preferred solution, since it changes the coordinates system of the sprite (right becomes left, left becomes right).

Quote
There could also be the same functions for sf::texture in order to flip the texture whatever way you want before the setTexture() call.
Such functions are in sf::Image.
Title: Re: Inverting a texture/sprite
Post by: masskiller on November 10, 2012, 05:10:51 pm
It seems I didn't check the doc well enough. I guess that's what you get for focusing two entire weeks on game art and not programming anything. Thanks for the help.