Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get touch location from touchesBegan? (And other game questions)

I'm trying to get the location of the touch event on the screen from

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event.

What code can I use to read the touch coordinates? I've gotten this far so far:

NSLog(@"Touch data: %@", [NSString stringWithFormat:@"NSSet: %@",[touches description]]);

I'm trying to make a game using an OpenGL template application. The touches will only register in the EAGLView file, not the ESRenderer1 file. I assume that I should use the EAGlView to set variables and then read the variables from there into the ESRenderer to perform game calculations. Is this a good approach?

like image 462
Moshe Avatar asked Jul 04 '10 21:07

Moshe


1 Answers

The following code does it:

NSArray *touchesArray = [touches allObjects];
for(int i=0; i<[touchesArray count]; i++)
{
    UITouch *touch = (UITouch *)[touchesArray objectAtIndex:i];
    CGPoint point = [touch locationInView:nil];

    // do something with 'point'
}
like image 163
Jim Buck Avatar answered Sep 20 '22 07:09

Jim Buck