Revert the texture coordinates by "inverting" the texture rect: sprite.setTextureRect(sf::IntRect(right, top, -width, height));
Revert the texture coordinates by "inverting" the texture rect: sprite.setTextureRect(sf::IntRect(right, top, -width, height));
Perfect answer there sir.
A simple check on a stored "Flipped" bool flag will allow me to choose weather I use positive or negative width.
Seriously, the lack of FlipX on sprite is a serious game-breaker for me.
No, it's not. FlipX/FlipY were just redundancies in the API. Even now, you still have multiple options to achieve the same thing. Either you do as Laurent suggested, or you use a negative scale factor (in this case, it will be an advantage if the origin is centered).
Perhaps I should have worded my statement a little better, it isn't the specific function FlipX/FlipY that is required, but an easy means on reproducing the effect.
The answer supplied by Laurent is basically my option 3: he explained to me how to recreate FlipX on an sf::Sprite object.
Small untested example.
FlipX(bool flipped)
{
Flipped = flipped; //store it in my class
if((flipped && getTextureRect().width > 0) || (!flipped && getTextureRect().width < 0))
{
sf::IntRect rect = getTextureRect();
rect.width = -rect.width;
setTextureRect(rect);
}
}
of course with something so simple as this, I'd need to encorporate the -width functionality into all my functions that change the SubRect as well, hence why I stored flipped in my class in the example.
There's nothing that prevents you from providing global functions
void flipX(sf::Sprite& sprite, bool flipped);
void flipY(sf::Sprite& sprite, bool flipped);
for ease of use.
If you don't want the texture rect to be affected by the flipping, then use the scale approach.
There's nothing that prevents you from providing global functions
void flipX(sf::Sprite& sprite, bool flipped);
void flipY(sf::Sprite& sprite, bool flipped);
for ease of use.
If you don't want the texture rect to be affected by the flipping, then use the scale approach.
Already half way done adding it to my AnimSprite class. Though I'll have to go back to my collision detection and add in compensation to ignore the sign on width and height. I think there's a function in math.h to strip a sign, but I can't remember it's name. Still, an easy fix.
I thank you for your sugestion though, your help is much apreciated.