1
\$\begingroup\$

I am facing the same problem although the sprite flips but only one time after that it does not flips at all. Here is the code snippet:

void Doodle::moveLeft()
{
    if(d_Right)
        d_Sprite.setScale(-1.0f, 1.0f);
    d_Left = true;
}

void Doodle::moveRight()
{
    if(d_Left==false)
        d_Sprite.setScale(-1.0f, 1.0f);
    d_Right = true;
}

void Doodle::stopLeft()
{
    d_Left = false;
}

void Doodle::stopRight()
{
    d_Right = false;
}
\$\endgroup\$
0
\$\begingroup\$
void Doodle::moveLeft() { if(d_Right) d_Sprite.setScale(-1.0f, 1.0f); d_Left = true; }

void Doodle::moveRight() { if(d_Left==false) d_Sprite.setScale(-1.0f, 1.0f); d_Right = true; }

This code is exactly the same, specifically: d_Sprite.setScale(-1.0f, 1.0f), this only flips it one way, you have to change this to flip it back.

\$\endgroup\$
0
\$\begingroup\$

The setScale function overwrites the previous scale. You just need to set the scale to 1 to get the original sprite.

void Doodle::moveLeft()
{
    d_Sprite.setScale(-1.0f, 1.0f);
}

void Doodle::moveRight()
{
    d_Sprite.setScale(1.0f, 1.0f);
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.