Hi,
somewhere i read you shouldn't use scale, but setScale(x,y). You could also check before you flip and don't set the scale in every timeframe.
In my project i did st like this (it' s also executed in an update loop)
void SpritesheetAnimation::flipAnimationLeft() {
if (mSprite.getScale().x != -1) {
// do not ever use mSprite.scale({x,y}) !!!
mSprite.setScale({-1, 1});
}
}
void SpritesheetAnimation::flipAnimationRight() {
if (mSprite.getScale().x != 1) {
// do not ever use mSprite.scale({x,y}) !!!
mSprite.setScale({1, 1});
}
}
And at the appropriate location in the code:
if(event.type == sf::Event::KeyPressed)
{
switch (event.key.code)
{
case sf::Keyboard::D:
case sf::Keyboard::Right:
{
playerCharacter->handleInput(EInput::PressRight);
playerCharacter->getSpriteAnimation().flipAnimationRight();
playerCharacter->setMoveDirection(EMoveDirection::Right);
break;
}
case sf::Keyboard::A:
case sf::Keyboard::Left:
{
playerCharacter->handleInput(EInput::PressLeft);
playerCharacter->getSpriteAnimation().flipAnimationLeft();
playerCharacter->setMoveDirection(EMoveDirection::Left);
break;
}