views:

57

answers:

1

Hi, I am a newbee in iPhone game development. What I want is that wherever user touches on iPhone screen, where I will display a pic at that place. Can anyone help me how to get co-ordinates of the area everytime when user touches the screen?

Regards, Nouman

A: 

You don't say you are using cocos2d, but you tagged your question as such. I will assume this is the case.

You need to put code in your ccTouchesEnded function. This is basically what it looks like:

-(BOOL)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
     UITouch *touch = [touches anyObject];
     CGPoint location = [touch locationInView: [touch view]];

     CCSprite *myImage = [CCSprite spriteWihFile: @"myImage.png"];
     [myImage setPosition: location];
     [self addChild: myImage];

     return YES;
 }

It sounds like you might need more help than that. If so, you should go to the cocos2d iphone page and look through the setup and tutorials.

Jeff B