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

Author Topic: Could somebody please elaborate on Sprite.SetCenter()?  (Read 3490 times)

0 Members and 1 Guest are viewing this topic.

Howitzer21

  • Newbie
  • *
  • Posts: 16
    • View Profile
Could somebody please elaborate on Sprite.SetCenter()?
« on: February 18, 2012, 06:16:13 am »
Hello.  Sorry for asking such a rudimentary question, but I've read the appropriate tutorials and documentation, as well as played around with it some, and I haven't been able to figure it out so far.  Could somebody please elaborate on Sprite.SetCenter()?

The reason I'm asking this is that it seems to be doing a lot more than I'm able to figure out.  It looks like it's basically supposed to set the center of rotation (the tutorial also says translation and scaling), but it's doing a lot more than just telling Sprite.Rotate() what point to rotate the image around.  If I set it to the center of the sprite, for instance, and then try to rotate it, the sprite does NOT necessarily rotate around its center.  Furthermore if I set it to the center of the sprite and don't try to rotate it or anything, the sprite's position automatically translates about half the sprite's width and height?

?  This has confused me severely.  I have worked with graphics before, and I am certainly familiar with rotation, translation, and scaling, but I'm having a lot of trouble seeing what Sprite.SetCenter() is really doing.  The only stuff I've been able to find basically just says that it sets the center for translation, rotation, and scaling, but as it's doing what seems (on the surface, in the eyes of an SFML nubie) a bunch of different, random things, I really need a more thorough description of what this function is.  Any help would be appreciated.  Thanks!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Could somebody please elaborate on Sprite.SetCenter()?
« Reply #1 on: February 18, 2012, 08:57:26 am »
Center has been renamed to Origin in SFML 2. I think it already makes things a little clearer.

Quote
If I set it to the center of the sprite, for instance, and then try to rotate it, the sprite does NOT necessarily rotate around its center

It should. Can you provide a small example that demonstrates this problem?

Quote
Furthermore if I set it to the center of the sprite and don't try to rotate it or anything, the sprite's position automatically translates about half the sprite's width and height?

The position property of the sprite refers to the center (because the center is also the origin of the translation). So if you change the center and not the position, the sprite automatically moves so that it's the new center point which is now at "position".

If you're familiar with transformations and coordinate systems, just think the center as the origin of the local coordinate system of the sprite. That's all.
Laurent Gomila - SFML developer

Howitzer21

  • Newbie
  • *
  • Posts: 16
    • View Profile
Could somebody please elaborate on Sprite.SetCenter()?
« Reply #2 on: February 20, 2012, 05:45:14 pm »
Sorry, I was taking a break from my project for a few days.  I just now used some modifications with the sprites tutorial, and combining it with what you said, figured out what was going wrong in my project (in theory).  Apparently the position properties interact with the center/origin of the sprite, not necessarily the upper-lefthand corner.  This would be the reason you were saying it was supposed to translate like that without the position being reset; therefore it has to be immediately translated right back to where it was before the rotations occur, taking what was done previously for the 0,0 center and adapting it to whatever the center is now. (if it's supposed to just spin around in place).  Thanks for the help, Laurent!