SFML community forums

General => Feature requests => Topic started by: DarkGlitch on January 11, 2013, 11:06:29 pm

Title: sf::Sprite::FlipX/Y
Post by: DarkGlitch on January 11, 2013, 11:06:29 pm
Bring this back.

This was the main reason I started using SFML, among other reasons, and now that I'm changing my project over to 2.0 I'm learning about all the things I took for granted in 1.6 that aren't in 2.0

That really made things SIMPLE as SFML is supposed to be and I think that made the Sprite class so freaking sexy.

I know I can just use a negative scale value, but FlipX made it so easy to flip a sprite with just a true or false I could hug Laurent on sight if I lived nearby.

On the other hand, changing IntRect's constructor was genius.

Edit: http://en.sfml-dev.org/forums/index.php?topic=9666.0

I should learn to use the search function. Sorry.
Title: Re: sf::Sprite::FlipX/Y
Post by: eXpl0it3r on January 11, 2013, 11:12:07 pm
So you actually already know, that the feature request won't be accepted, but you still ask for it? ::)
Title: Re: sf::Sprite::FlipX/Y
Post by: DarkGlitch on January 11, 2013, 11:38:29 pm
I can hope. XD

No seriously, I just thought well if you're gonna change IntRect, which I agree with, why change Sprite when, imo it was perfect.
Title: Re: sf::Sprite::FlipX/Y
Post by: eXpl0it3r on January 12, 2013, 12:14:12 am
The change of IntRect and FlipX/Y are not really comparable, since IntRect was changed, because of its more logical use x,y,width,height while not affecting the performance in calculating the 'third' information (instead of x2-x1 = width you now get x1+widht = x2).

FlipX/Y on the other hand was removed to clean-up the API and remove redundant functionalities. Since one can simply set a negative scale factor to flip a sprite and the scale function gets implemented anyway, the FlipX/Y just aren't needed anymore.

Arguing about simplicity of FlipX/Y vs. scale with negative factor isn't very strong, since both ways have the same simplicity to use.

The only argument I see as valid, is that FlipX/Y would be more descriptive than the scale function. But I happily take a cleaner API over a small bit of readability. ;)
Title: Re: sf::Sprite::FlipX/Y
Post by: cire on January 12, 2013, 01:37:53 am
Quote
That really made things SIMPLE as SFML is supposed to be and I think that made the Sprite class so freaking sexy.

void flipX(sf::Sprite & s )
{
    auto rect= s.getTextureRect() ;

    rect.left += rect.width ;
    rect.width = -rect.width ;

    s.setTextureRect(rect) ;
}

void flipY(sf::Sprite& s)
{
    auto rect = s.getTextureRect() ;

    rect.top += rect.height ;
    rect.height = -rect.height ;

    s.setTextureRect(rect) ;
}

There.  It's all sexy again.
Title: Re: sf::Sprite::FlipX/Y
Post by: waxx on January 24, 2013, 12:49:46 pm
Doesn't that screw things up with a) subrects b) origins though?
Title: Re: sf::Sprite::FlipX/Y
Post by: eXpl0it3r on January 24, 2013, 01:05:11 pm
Doesn't that screw things up with a) subrects b) origins though?
Depends what you understand under 'screw up'.
As you see it simply negates the subrect, thus there shouldn't be a problem. Flipping around an axis will of course change the look of the image, thus if you don't apply transformation on the middle of the sprite, things could potentially look not the way you want them, but that's also the case for the old 'native' FlipX/Y.
Title: Re: sf::Sprite::FlipX/Y
Post by: Halsys on February 17, 2013, 01:02:53 am
You can flip a sprite if you give them a negative scale...
sf::Sprite RandomSprite;
RandomSprite.setOrgin(RandomSprite.getGlobalBounds().width/2,RandomSprite.getGlobalBounds().height/2)//So the orgin(aka center) is in the center.
RandomSprite.Scale(-1,-1);//Flips and Backward
RandomSprite.Scale(-1,1);//Backwards
RandomSprite.Scale(1,-1)//Flips
 
Your welcome... Maybe should be said somewhere in docs that you can get away with this.
Title: AW: sf::Sprite::FlipX/Y
Post by: eXpl0it3r on February 17, 2013, 08:22:31 am
I think it was already clear that scaling with a negative value will do the trick, but we were more discussing the API changes.
Btw from a design standpoint, chang in the texture rect is imho the cleaner way to do it.
Title: Re: sf::Sprite::FlipX/Y
Post by: Halsys on February 17, 2013, 08:48:13 am
You mean its cleaner because you keep your origin and original scale? Well from that point of view, yeah.
But because I use Box2D in my current project and I have to use the center of each physics piece to draw... and a couple times before I had to "Flip it"... It was perfect/fast enough for me. Its a personal preference. :P