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

Author Topic: Flip Sprite setScale problem  (Read 795 times)

0 Members and 1 Guest are viewing this topic.

Jan666

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Flip Sprite setScale problem
« 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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10800
    • View Profile
    • development blog
    • Email
Re: Flip Sprite setScale problem
« Reply #1 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)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

kojack

  • Sr. Member
  • ****
  • Posts: 299
  • C++/C# game dev teacher.
    • View Profile
Re: Flip Sprite setScale problem
« Reply #2 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.


Jan666

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Re: Flip Sprite setScale problem
« Reply #3 on: May 20, 2022, 01:40:18 pm »
Thank you

 

anything