Hi guys.
I am currently implementing spritesheets into my game rather than having static images moving around all over the places.
For this, I am using the source provided on the Github wiki: https://github.com/SFML/SFML/wiki/Source%3A-AnimatedSprite
It's working just fine, except I am having some trouble flipping the sprite when the character is moving in the opposite direction of the spritesheet.
I have a little trouble wrapping my head around how it should be done, as the AnimatedSprite class isn't inheriting from sf::Sprite, so that I can't do the simple:
// flip X
sprite.setTextureRect(sf::IntRect(width, 0, -width, height));
Has anyone implemented a such feature in their AnimatedSprite class? If so, how did you do it?
Thanks for your time.
Try passing a negative number to setScale().
Tried implementing a AnimatedSprite::flipTexture() function:
void AnimatedSprite::flipTexture()
{
setOrigin(getGlobalBounds().width/2, 0);
setScale(-1.f,1.f);
setOrigin(0, 0);
}
But I am having some trouble with the sprite changing position. Am I using the setOrigin correctly?
EDIT: This appears to work:
void AnimatedSprite::flipTexture()
{
setOrigin(getGlobalBounds().width, 0);
setScale(-1.f,1.f);
}
Will I face any problems with having a modified origin?