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

Author Topic: Flipping sprite not working.  (Read 1217 times)

0 Members and 1 Guest are viewing this topic.

mtbds

  • Newbie
  • *
  • Posts: 1
    • View Profile
Flipping sprite not working.
« on: March 25, 2016, 05:40:43 am »
Well, I was trying to flip a sprite using the following code, but it's not working, I'm getting a red square instead of my flipped sprite.

if (pPhysics->getLeft())
        {
                //pRender->getSprite().setScale(-1, 1);
                pRender->getSprite().setTextureRect(sf::IntRect{ (int)m_currentFrame * pRender->getWidth(), 0, pRender->getWidth(), -pRender->getHeight() });
        }
        else
        {
                //pRender->getSprite().setScale(1, 1);
                pRender->getSprite().setTextureRect(sf::IntRect{ (int)m_currentFrame * pRender->getWidth(), 0,  pRender->getWidth(), pRender->getHeight() });

        }
 

Images:
Looking right : http://puu.sh/nT5FY/eb708201f9.png
Looking left : http://puu.sh/nT5Hp/d3d04b2ee5.png
Sprite : http://puu.sh/nT5IO/0d4937a37d.png

I don't know if I made something wrong on my code, or if it's just a bug...

Peace.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Flipping sprite not working.
« Reply #1 on: March 25, 2016, 09:05:08 am »
IntRect{ (int)(m_currentFrame + 1) * pRender->getWidth(), 0, -pRender->getWidth(), pRender->getHeight() });
Laurent Gomila - SFML developer

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11029
    • View Profile
    • development blog
    • Email
AW: Flipping sprite not working.
« Reply #2 on: March 25, 2016, 09:54:15 am »
Why do you use a negative height?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/