Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Inverting a texture/sprite  (Read 3669 times)

0 Members and 1 Guest are viewing this topic.

masskiller

  • Sr. Member
  • ****
  • Posts: 284
  • Pointers to Functions rock!
    • MSN Messenger - kyogre_jb@hotmail.com
    • View Profile
    • Email
Inverting a texture/sprite
« 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]
Programmer, Artist, Composer and Storyline/Script Writer of "Origin of Magic". If all goes well this could turn into a commercial project!

Finally back into the programming world!

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Inverting a texture/sprite
« Reply #1 on: November 10, 2012, 12:28:28 am »
scaling by -1,1 ...
Back to C++ gamedev with SFML in May 2023

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Inverting a texture/sprite
« Reply #2 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.
Laurent Gomila - SFML developer

masskiller

  • Sr. Member
  • ****
  • Posts: 284
  • Pointers to Functions rock!
    • MSN Messenger - kyogre_jb@hotmail.com
    • View Profile
    • Email
Re: Inverting a texture/sprite
« Reply #3 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.
Programmer, Artist, Composer and Storyline/Script Writer of "Origin of Magic". If all goes well this could turn into a commercial project!

Finally back into the programming world!