Wrong x,y coordinates with Texture2D class

Nibbie
Posts: 2
Joined: 2009.02
Post: #1
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
Quote this message in a reply
Member
Posts: 320
Joined: 2003.06
Post: #2
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.

Chopper, iSight Screensavers, DuckDuckDuck: http://majicjungle.com
Quote this message in a reply
Nibbie
Posts: 2
Joined: 2009.02
Post: #3
Oh god !
Yes it is simply that ^^

For drawAtPoint, it centres the texture Wink

Thank you a lot man ! =)
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Texture2d crash lander ajrs84 0 2,789 Apr 1, 2012 08:54 AM
Last Post: ajrs84
  OpenAL, i am doing it wrong or is it broken on iPad simulator? AdrianM 3 4,213 Apr 23, 2010 11:18 AM
Last Post: Rasterman
  Problem using Texture2D sub-section bendell 0 2,443 Mar 20, 2010 02:06 AM
Last Post: bendell
  Create a texture2d with contents of other textures godexsoft 6 4,546 Nov 12, 2009 10:24 PM
Last Post: godexsoft
  OpenGL ES and Texture2D Talyn 37 31,412 Jul 30, 2009 09:34 AM
Last Post: Splat21