views:

517

answers:

1

Hi,all, me again with another noob Cocos2d iphone question.

I've set my Director to Landscape, but when I was looking at the coordinates of the 'Touch Event' it was still picking them up as though the screen was portrait. So they were basically reversed.

x = 100, y = 50

should have been

x = 50, y = 100

No biggie, it was easily fixed by creating a new CGPoint and swapping the values around. However, it feels like there should be some neater way to do this. But I've not been able to find any reference to it. Is this the only way to do it or is there something built into Cocoa Touch or Cocos2d to fix this.

off topic: My God, iPhone is such a nice platform to develop for. And Obj-C is as cool as a cucumber. Sorry I just had to get that out of my system, non of my friends are programmers. They don't understand the pain of Internet explorer.

+3  A: 
/** converts a UIKit coordinate to an OpenGL coordinate
 Useful to convert (multi) touchs coordinates to the current layout (portrait or landscape)
 */
-(CGPoint) convertCoordinate: (CGPoint) p;

See Director.h:166.

Use it like this:

cocosTouchPoint = [[Director sharedDirector] convertCoordinate:touchPoint];
lhunath