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

Author Topic: [SOLVED] Am I setting the position of the center of the sprite?  (Read 956 times)

0 Members and 1 Guest are viewing this topic.

Yannbane

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
[SOLVED] Am I setting the position of the center of the sprite?
« on: February 19, 2013, 08:33:08 pm »
After a call to the 'set_image' method of the object class, which acts as an abstraction over sf::Sprite::SetImage, I always set the sprites center to the half of images width and height.

I do this because it seems to be necessary to get Box2D rotation to work.

However, after I've set a different than default (0, 0) sprite center, does that mean that when I call sf::Sprite::SetPosition I'm actually setting the position of the center?
« Last Edit: February 19, 2013, 08:52:15 pm by Yannbane »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Yep. The center is the origin of all the transformations (translation, rotation, scale).
Laurent Gomila - SFML developer

Yannbane

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
I just found this:
SetCenter is not the center (middle) of the shape, which would have to be calculated from the points.

SetCenter is the center (origin) of all transformations that you apply to it (SetPosition, SetRotation, SetScale), it changes only if you call SetCenter so it is always (0, 0) by default.

It is easy to see that the shape's points and the center are completely unrelated: the formers are defined in sf::Shape while the latter is a generic attribute defined in sf::Drawable (which known nothing about its derived classes).

And yes, "center" is a confusing name, it was renamed to "origin" in SFML 2 ;)

Thanks a lot.