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

Author Topic: Don't understand after call method: SetCenter(x, y)  (Read 1350 times)

0 Members and 1 Guest are viewing this topic.

vietean

  • Newbie
  • *
  • Posts: 1
    • View Profile
Don't understand after call method: SetCenter(x, y)
« on: March 28, 2011, 05:16:54 am »
Hello all,

I don't understand a issue about what is changed after calling method: SetCenter(float x, float y) of Rect shape.

For example:
I declare a: Rect(0,0, 100, 100)
Then I call: SetCenter(50,50)
Why:
Now I move: -50, -50 from topleft position as below image:



Thanks in advanced.

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Don't understand after call method: SetCenter(x, y)
« Reply #1 on: March 28, 2011, 06:16:26 am »
SetCenter sets the center or origin of the drawable. So when you give the drawable a position this is the position that will be in center when drawing.

http://www.sfml-dev.org/documentation/1.6/classsf_1_1Drawable.htm#11ba1d92bc863af6d95831d216802f61

If you have a drawable which has the position [100, 100] and the center is set to [10, 10]. Then the drawable will be drawn at the position [100,100] but with an offset by [-10,-10]. This method is here to help you out as this is something common people do to position their drawables on screen correctly. So instead of yourselves writing the math on several places in your code, you just have one SetCenter function instead.

This method was renamed in SFML2 to SetOrigin instead to be more clear with it's intended purpose.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

 

anything