Cocoa – multiple touch problem in Cocoa touch/i-phone

cocoa-touch

I am going to develop a ball game where i have to touch two/more
ball simultaneously.So how will i detect these multiple touch.
I came to know the following way i can detect multiple touch-

-(void)touchesBegan:(NSSet*)toucheswithEvent:(UIEvent*)event

{
UITouch* touch = [touches anyObject];
NSSet *touch2 = [event allTouches];
[touch2 count] //which count no. of touches

}

which detect only no. of touch. But I need to find out the (x-co-ordinate,y-co-ordinate) of these touch point.Not only this when i throw (means touch inside a ball and then slide the cursor) these ball how will i identify which ball is moving(means touchmove will identify which touchbegan??and if for each ball touchmove is called then how will i reset ball position because i gettting two touchposition(x1.x2) and (x2,y2) for 2 ball,so how will i say which ball belongs to (x1,y2) or (x2,y2)) .

Best Answer

In your code about touch2 is a set of UITouch objects

You can get at each object like so:

UITouch *touch = [[touch2 allObjects] objectAtIndex:0];

EDIT: to add information about touchesMoved

touchesBegan is called when one or more fingers is placed on the screen. At this point you will need to determine which ball corresponds to each touch (by using the coordinates of each touch). You will need to store this mapping.

touchesMoved will be called continually as the fingers are moved across the screen. Using the mapping you calculated earlier, you can determine which ball corresponds to which UITouch and apply some movement to it as you see fit.

Perhaps you should read handling a complex multi-touch sequence in the apple docs.