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

Author Topic: Sfml 2.0 Flipping a sprite  (Read 34696 times)

0 Members and 1 Guest are viewing this topic.

ayzed

  • Newbie
  • *
  • Posts: 9
    • View Profile
Sfml 2.0 Flipping a sprite
« on: April 12, 2012, 04:52:06 am »
Is there a way to flip a sprite as easy as FlipX() in sfml 1.6 ???

ChonDee

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
Re: Sfml 2.0 Flipping a sprite
« Reply #1 on: April 12, 2012, 07:55:25 am »
Sprite.Scale(-1.f,1.f); is the simplest way as far as I know

ayzed

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Sfml 2.0 Flipping a sprite
« Reply #2 on: April 12, 2012, 03:46:00 pm »
Using scale change the position too, I don't want that,how can i solve it?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Sfml 2.0 Flipping a sprite
« Reply #3 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).
Laurent Gomila - SFML developer

ayzed

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Sfml 2.0 Flipping a sprite
« Reply #4 on: April 12, 2012, 04:44:21 pm »
it works :D
somthing else, why animations from sprites are buggy and sometimes the images disappear?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Sfml 2.0 Flipping a sprite
« Reply #5 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?
Laurent Gomila - SFML developer

ayzed

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Sfml 2.0 Flipping a sprite
« Reply #6 on: April 12, 2012, 05:16:28 pm »
nvm, thank you for you fast answers :D :D :D

arjungmenon

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: Sfml 2.0 Flipping a sprite
« Reply #7 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 ?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Sfml 2.0 Flipping a sprite
« Reply #8 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.
Laurent Gomila - SFML developer

Battleapple

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Sfml 2.0 Flipping a sprite
« Reply #9 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?

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Sfml 2.0 Flipping a sprite
« Reply #10 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));

Battleapple

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Sfml 2.0 Flipping a sprite
« Reply #11 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  :)

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Sfml 2.0 Flipping a sprite
« Reply #12 on: December 26, 2013, 11:17:07 pm »
The correct values are the values you use to draw the sprite normally, simply. :p