iDevGames Forums
Wrong x,y coordinates with Texture2D class - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: iPhone, iPad & iPod Game Development (/forum-11.html)
+--- Thread: Wrong x,y coordinates with Texture2D class (/thread-1774.html)



Wrong x,y coordinates with Texture2D class - Minishlink - Feb 11, 2009 12:03 PM

Hi everyone ! Smile

I'm currently creating a game with OpenGL|ES and the Texture2D class which is from Apple.
But the x,y coordinates seems to be wrong with a little code like :

Code:
pos.x = _touch.x
pos.y = _touch.y

_textures[kTexture_Player] = [[Texture2D alloc] initWithImage: [UIImage imageNamed:@"Player.png"]];

glLoadIdentity();

glPushMatrix();
glTranslatef(player.x, 460 - player.y, 0);
[_textures[kTexture_Player] drawAtPoint:CGPointMake(0, 0)];
glPopMatrix();

Here when I touch the screen, the player is not at x,y coordinates of my touch !
I have to "CGPointMake(0, 16)" to have it at right coordinates...

This is with CGPointMake(0,0) :
http://h4xr.org/cdqi

And with my "handcrafted" CGPointMake(0,16) it is approximately in the center of my touch.

Can you help me ?

Thanks. Smile


Wrong x,y coordinates with Texture2D class - reubert - Feb 11, 2009 11:46 PM

I think you want 480-y. Your view is probably 480 pixels high when the status bar is hidden.

And I'm not sure how exactly drawAtPoint works, but it may not be centered, so if this is the case you will have to offset it by half the texture size.


Wrong x,y coordinates with Texture2D class - Minishlink - Feb 12, 2009 11:37 AM

Oh god !
Yes it is simply that ^^

For drawAtPoint, it centres the texture Wink

Thank you a lot man ! =)