SFML community forums

Help => Graphics => Topic started by: PanZWarzywniaka on April 24, 2020, 06:15:27 pm

Title: Transformations igrnores sf::Sprite's origin
Post by: PanZWarzywniaka on April 24, 2020, 06:15:27 pm
Transforming a sprite, does not regard it's new origin.

In my case sf::Sprite is rotating around the axis that is in the left top corner ({0,0}) regardless its origin. Setting new origin with .setOrigin() earlier takes no effect.

My code:

In each of my Card class constructors I set the origin of my sprite.

card_sprite.setOrigin(Card::get_default_single_card_size().x*Game::get_scale()/2,Card::get_default_single_card_size().y*Game::get_scale()/2);
 

And then in my Deck class which behaves like std::stack of Cards I use function:

void Deck::push(const Card& crd)
{
    push_back(crd);
    ..//
    std::default_random_engine generator;
    std::uniform_real_distribution<float> distributor(0,360);
    top().setRotation(distributor(generator));
}
 

Card::setRotaion() looks like this, (which a I said still rotates card around top left corner):

void Card::setRotation(float angle)
{
    card_sprite.setRotation(angle);
}
 

Thanks for help in advance.
Title: Re: Transformations igrnores sf::Sprite's origin
Post by: Laurent on April 24, 2020, 06:33:45 pm
What's the local size (getLocalBounds()) of card_sprite? What the value of Card::get_default_single_card_size().x*Game::get_scale()/2 and Card::get_default_single_card_size().y*Game::get_scale()/2?