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

Author Topic: Transformations igrnores sf::Sprite's origin  (Read 1289 times)

0 Members and 1 Guest are viewing this topic.

PanZWarzywniaka

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
Transformations igrnores sf::Sprite's origin
« 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Transformations igrnores sf::Sprite's origin
« Reply #1 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?
Laurent Gomila - SFML developer