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?
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'
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With