tags:

views:

158

answers:

1

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)) .

A: 

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.

Alex Deem
thanx for reply,but [[allTouches allObjects] objectAtIndex:0] does not work.No method is found like this.Plz say exact function.
russell
Sorry,now i got the meaning of "allTouches is a set of UITouch objects".thanx for reply.But can anyone answer my second question.
russell
I edited the answer to clear up my meaning of 'allTouches', and add information about touchesMoved.
Alex Deem
When you get a touchesBegan: you can keep a map between touches and balls; when you get a touchesMoved:, consult this map to determine which ball to move.
Ben Stiglitz