SFML community forums

Help => Graphics => Topic started by: Jan666 on May 20, 2022, 06:52:54 am

Title: Flip Sprite setScale problem
Post by: Jan666 on May 20, 2022, 06:52:54 am
Hello,
Maybe someone knows a solution. I have setScale(3 ,3.5) my Sprite coz its too small. But when i used setScale again to flip my sprite with (-1 ,1) when it move to left, the Sprite get small. Is there any way to safe the first setScale values for the Sprite? I dont wanna use other ways like for example IntRect(0,0,-weight, height) coz i used a Spritesheet and its getting to complicated with the animation.
Title: Re: Flip Sprite setScale problem
Post by: eXpl0it3r on May 20, 2022, 07:48:21 am
setScale sets an absolute new scale, so nothing is "saved".
If you call scale(-1, 1) it would apply to the existing scale.
Alternatively, you can just call setScale(-3, 3.5f)
Title: Re: Flip Sprite setScale problem
Post by: kojack on May 20, 2022, 11:12:50 am
You could read back the current values and use them:
To make it flipped (regardless of whether it's already flipped or not):
sprite->setScale(-fabs(sprite->getScale().x), sprite->getScale().y);

To make it not flipped (also regardless of current flip):
sprite->setScale(fabs(sprite->getScale().x), sprite->getScale().y);

fabs is the floating point absolute, it makes numbers positive. So -fabs makes numbers negative.

Title: Re: Flip Sprite setScale problem
Post by: Jan666 on May 20, 2022, 01:40:18 pm
Thank you