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

Author Topic: Sprite::GetPosition()  (Read 14800 times)

0 Members and 1 Guest are viewing this topic.

ravenheart

  • Full Member
  • ***
  • Posts: 148
    • View Profile
Sprite::GetPosition()
« on: January 02, 2009, 07:58:57 pm »
What exactly does GP return?
i thought it would return the position of the top left corner of a sprite.

now i have done following:
i reset the center of my sprite, and somehow my sprites position on screen changed too, what is the relationship between

Center and Position of a sprite?

and what does happen to the position if i rotate my sprite?

will the position still be the same or will it only be the same if rotationcenter and position are the same?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Sprite::GetPosition()
« Reply #1 on: January 03, 2009, 11:00:01 am »
Quote
What exactly does GP return?

It returns the position of the origin (center) of the sprite. By default the center is the top-left corner, but you can change it.

Quote
i reset the center of my sprite, and somehow my sprites position on screen changed too, what is the relationship between Center and Position of a sprite?

Because Position is the position of Center, if you move the center within the sprite, its visual position will change too.

Quote
and what does happen to the position if i rotate my sprite?

As I said, Position is the position of the Center. And Center is the center of all transformations, including rotation. So it will never change regarding rotation and scaling.
Laurent Gomila - SFML developer

ravenheart

  • Full Member
  • ***
  • Posts: 148
    • View Profile
Sprite::GetPosition()
« Reply #2 on: January 03, 2009, 04:25:41 pm »
ok so far so good

only one more thing what happens if i set my center OUTSIDE the sprite?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Sprite::GetPosition()
« Reply #3 on: January 03, 2009, 04:35:45 pm »
Quote
what happens if i set my center OUTSIDE the sprite?

Nothing more than when you set it inside ;)
Laurent Gomila - SFML developer

ravenheart

  • Full Member
  • ***
  • Posts: 148
    • View Profile
Sprite::GetPosition()
« Reply #4 on: January 06, 2009, 01:11:59 pm »
well now i want to do something like that:

i have a window 400*400px
and i want two sprite to rotate round the center of the window
but i do want to know the distance between the two sprites too

is there any easy way to do it?

if i set the center of both in the middle of window, i cant work with GetPos anymore?

ravenheart

  • Full Member
  • ***
  • Posts: 148
    • View Profile
Sprite::GetPosition()
« Reply #5 on: January 06, 2009, 06:51:38 pm »
is it neccessary that i write my own fuctions?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Sprite::GetPosition()
« Reply #6 on: January 06, 2009, 07:06:44 pm »
Sorry, I don't understand why you're trying to achieve.
Laurent Gomila - SFML developer

ravenheart

  • Full Member
  • ***
  • Posts: 148
    • View Profile
Sprite::GetPosition()
« Reply #7 on: January 06, 2009, 07:14:19 pm »
ok ill try to explain

i have two sprites that should go in circles
center of the rotation is the midle of the screen
i need the distance between the two sprites'

when i set the center of rotation = middle of screen, getposition will not return different values for both sprites

am i right?

quasius

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Sprite::GetPosition()
« Reply #8 on: January 06, 2009, 08:18:57 pm »
Quote from: "ravenheart"
ok ill try to explain

i have two sprites that should go in circles
center of the rotation is the midle of the screen
i need the distance between the two sprites'

when i set the center of rotation = middle of screen, getposition will not return different values for both sprites

am i right?


Yes, you are right.  GetPosition will return the same value since you're not actually moving them.  The reason is that you're misusing rotation to attempt to set the rendered position as well.  If you want rotational movement about a center point, you should calculate the new position yourself and set that position.

dsdevil

  • Newbie
  • *
  • Posts: 11
    • View Profile
Sprite::GetPosition()
« Reply #9 on: February 15, 2011, 09:21:19 pm »
Hello!
What really does the GetPosition return? "Cout" cant display it. I really dont get it. Witch type does it return?

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Sprite::GetPosition()
« Reply #10 on: February 15, 2011, 10:20:05 pm »
SFML / OS X developer

dsdevil

  • Newbie
  • *
  • Posts: 11
    • View Profile
Sprite::GetPosition()
« Reply #11 on: February 16, 2011, 07:16:43 pm »
Quote from: "Hiura"
The doc is your friend ;-)

http://www.sfml-dev.org/documentation/1.6/classsf_1_1Drawable.htm#9ad52594fd5e835cbd03b79098d70e0b


Wow! I didn't now about that part of the website. Thank you.