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

Author Topic: Sprite getPosition function giving wrong y value.  (Read 1718 times)

0 Members and 1 Guest are viewing this topic.

sokaroka

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Sprite getPosition function giving wrong y value.
« on: September 07, 2013, 04:27:17 pm »
So I have two sprites drawn.
The map and the player.
If I use getPosition on the map sprite and print it out it gives me 0, 0.
If I line up my player as close as I can to 0, 0.



Then print out the coords of the player as according to getPosition...
In that shot it tells me x is like -0.05, which looks correct, but as you can see the top of the player is BELOW the apparent 0 y point of the map, but I'm being told it's like -0.3, when as you can see it should be about 0.1 or whatever.

Is this a bug or am I doing something wrong or..I really have no idea and it caused great frustration as to why my collision function wasn't working.

EDIT: I thought I'd also add I'm using a view and the players position is set so that it's centered in the view.
« Last Edit: September 07, 2013, 04:32:30 pm by sokaroka »

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Sprite getPosition function giving wrong y value.
« Reply #1 on: September 07, 2013, 04:40:38 pm »
EDIT: I thought I'd also add I'm using a view and the players position is set so that it's centered in the view.

Due to some of the things OpenGL does internally when you have a view set at a position that is not a whole number (float instead of integer) you will not get pixels to lineup exactly. The best solution is to round your view's position to a whole number.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

sokaroka

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: Sprite getPosition function giving wrong y value.
« Reply #2 on: September 07, 2013, 04:44:03 pm »
EDIT: I thought I'd also add I'm using a view and the players position is set so that it's centered in the view.

Due to some of the things OpenGL does internally when you have a view set at a position that is not a whole number (float instead of integer) you will not get pixels to lineup exactly. The best solution is to round your view's position to a whole number.

Okay thank you very much, I'll give that a shot.

sokaroka

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: Sprite getPosition function giving wrong y value.
« Reply #3 on: September 07, 2013, 05:43:36 pm »
I'm still getting the same problem.

sokaroka

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: Sprite getPosition function giving wrong y value.
« Reply #4 on: September 07, 2013, 05:49:47 pm »
I'm still getting the same problem.

EDIT: I changed the player texture to 32x32 instead of 32x27 and now it's off by a different amount.

 

anything