SFML community forums

Help => Graphics => Topic started by: sokaroka on September 07, 2013, 04:27:17 pm

Title: Sprite getPosition function giving wrong y value.
Post by: sokaroka 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.

(http://puu.sh/4lgYc.png)

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.
Title: Re: Sprite getPosition function giving wrong y value.
Post by: zsbzsb 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.
Title: Re: Sprite getPosition function giving wrong y value.
Post by: sokaroka 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.
Title: Re: Sprite getPosition function giving wrong y value.
Post by: sokaroka on September 07, 2013, 05:43:36 pm
I'm still getting the same problem.
Title: Re: Sprite getPosition function giving wrong y value.
Post by: sokaroka 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.