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

Author Topic: flip image  (Read 5878 times)

0 Members and 1 Guest are viewing this topic.

player931402

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
flip image
« on: June 19, 2012, 11:55:20 am »
on my spritesheet I have the sprites that look to the right.

There is a fast mode to add the function to flip in SFML 2 ? ( MVC++ 10 )


for example:

in state "Run" i would to create something like:

if ( !isFlipped)
    sprite.setTextureRect(sf::IntRect(50*ActualXframe,50*ActualYframe,50,50))
else
 // select same textureRect But flipped.. how can i do this ?




Ty in advance :)

pdinklag

  • Sr. Member
  • ****
  • Posts: 330
  • JSFML Developer
    • View Profile
    • JSFML Website
Re: flip image
« Reply #1 on: June 19, 2012, 12:07:54 pm »
You can set the sprite's scale to a negative value.
E.g. to flip the sprite horizontally (X axis), set its scale to (-1, 1):

sprite.setTextureRect(sf::IntRect(50*ActualXframe,50*ActualYframe,50,50));

if(isFlipped)
  sprite.setScale(sf::Vector2f(-1, 1));
 

Note that this will require the sprite's origin to be in the center. The flipped sprite will appear 50 pixels off to the left if you do not correct the origin (which is the top left corner by default).
JSFML - The Java binding to SFML.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: flip image
« Reply #2 on: June 19, 2012, 12:17:02 pm »
I'll do a quick modification to sf::Sprite so that using a TextureRect with a negative height works too. It will be much easier to use than the negative scale -- it won't break the sprite's geometry.
Laurent Gomila - SFML developer

player931402

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Re: flip image
« Reply #3 on: June 19, 2012, 12:34:02 pm »
Great !

Ty pdinklag for help and.. Laurent I'll wait for your fix :)

pdinklag

  • Sr. Member
  • ****
  • Posts: 330
  • JSFML Developer
    • View Profile
    • JSFML Website
Re: flip image
« Reply #4 on: June 19, 2012, 01:39:33 pm »
I'll do a quick modification to sf::Sprite so that using a TextureRect with a negative height works too. It will be much easier to use than the negative scale -- it won't break the sprite's geometry.
Very good idea!
JSFML - The Java binding to SFML.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: flip image
« Reply #5 on: June 19, 2012, 06:35:37 pm »
Quote
Laurent I'll wait for your fix
Done.
Laurent Gomila - SFML developer

 

anything