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

Author Topic: New API, Sprite::FlipX() ?  (Read 3913 times)

0 Members and 1 Guest are viewing this topic.

eigenbom

  • Full Member
  • ***
  • Posts: 228
    • View Profile
New API, Sprite::FlipX() ?
« on: January 04, 2012, 02:02:06 am »
I've been using sprite.FlipX(true) a few times through my code, and after updating to the latest build, I see it's disappeared. Is there a simple way to implement the same functionality with the new API?

I tried sprite.Scale(-1,1) and using sf::Transform to no avail, but I'm also trying to avoid thinking about it too much. :P

jmcmorris

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
New API, Sprite::FlipX() ?
« Reply #1 on: January 04, 2012, 03:20:56 am »
I haven't tried this but I just looked at the code and from what I see you want to use Sprite::SetTextureRect() and pass in a negative width/height to flip the sprite as well as add the width/height to the x and y.

Code: [Select]
sf::Texture t;
sf::Sprite s;
//Flip the sprite vertically using the entire texture
s.SetTextureRect(0, t.GetHeight(), 0, -t.GetHeight());

eigenbom

  • Full Member
  • ***
  • Posts: 228
    • View Profile
New API, Sprite::FlipX() ?
« Reply #2 on: January 04, 2012, 03:27:15 am »
Thanks for the reply, I did try this method quickly but it didn't work. I'll give it a proper try later today ... :D

jmcmorris

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
New API, Sprite::FlipX() ?
« Reply #3 on: January 04, 2012, 07:03:22 am »
Hmmmm. I'm surprised that doesn't work. The version of SFML that I'm using has the older graphics API so I don't really have a way with playing around with this. But I am definitely curious since I use FlipX() & FlipY() and will eventually upgrade to a newer version of SFML.

thePyro_13

  • Full Member
  • ***
  • Posts: 156
    • View Profile
New API, Sprite::FlipX() ?
« Reply #4 on: January 04, 2012, 07:45:02 am »
Quote from: "jmcmorris"
I haven't tried this but I just looked at the code and from what I see you want to use Sprite::SetTextureRect() and pass in a negative width/height to flip the sprite as well as add the width/height to the x and y.

Code: [Select]
sf::Texture t;
sf::Sprite s;
//Flip the sprite vertically using the entire texture
s.SetTextureRect(0, t.GetHeight(), 0, -t.GetHeight());


A similar idea, but you should be using the setscale method. Call it with negative values to "flip" the image.

I haven't tested it, I think it works(from memory of something I read here on the forum).

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
New API, Sprite::FlipX() ?
« Reply #5 on: January 04, 2012, 07:55:02 am »
Using a negative scale works, but it will flip the sprite not only its texture. So either set the origin of the sprite to its center, or adjust its position accordingly.

Using negative texture coordinates might work too, but you have to explicitely set the texture as repeated (it's not by default) -- texture.SetRepeated(true).
Laurent Gomila - SFML developer

eigenbom

  • Full Member
  • ***
  • Posts: 228
    • View Profile
New API, Sprite::FlipX() ?
« Reply #6 on: January 05, 2012, 09:11:09 am »
Thanks guys. I adjusted the position after negatively scaling. Works like a treat.