Then probably introduced after the monitoring event, then the touch screen of the most concerned should be more contact;
-----get multi-touch nsset *alltouches = [Event Alltouches]; Uitouch *touchone = [[Alltouches allobjects]objectatindex:0]; Uitouch *touchtwo = [[Alltouches allobjects]objectatindex:1]; //... Analogy
Get more ruthless simple, then the basic commonly used to write down the following: 1-to determine whether the user clicks or double click (for a contact point)
if ([alltouches count]==1) { uitouch *touchone = [[allTouches allObjects]objectAtIndex:0]; switch ([Touchone tapcount]) { case 1: //Click cclog (@ "%@", @ "click"); break; case 2: //Double-click cclog (@ "%@", @ "double click"); break; } }
2-Determine whether the user's two contacts are closed or separate (for two contacts).
if ([alltouches count]==2) { //properly modified for processing, can not be taken at the same time, Otherwise it must be the same (can be one in the began one at end) uitouch *touchone = [ [alltouches allobjects]objectatindex:0]; uitouch *touchtwo = [[allTouches allObjects]objectAtIndex:1]; cgfloat *disFirst =[self distance:[touchOne locationInView:[self view]] todistance:[touchTwo locationinview:[self view]]]; UITouch *touchOne = [[allTouches allObjects]objectAtIndex:0];     UITOUCH&NBsp;*touchtwo = [[alltouches allobjects]objectatindex:1]; cgfloat *disfinal =[self distance:[touchone locationinview:[self view]] todistance:[touchTwo locationinview:[self view]]]; if (disfirst>disfinal) { cclog (@ "%@", @ "closure"); }else{ cclog (@ "%@", @ " Separate "); } }
Here I write roughly together, to determine whether two contacts are closed is actually the user just touch the distance between two points of the record to do Disfirst, and then two contacts left the screen (or moving events) when the calculation
The distance between the current two contacts is disfinal, then it is possible to know whether to close or separate according to the distance between Disfirst and disfinal;
(Cclog is the cocos2d package printing method that is not compiled into a program when compiling a formal game program, but NSLog will always exist.) Be aware. )
Finally, two functions are given to compute the coordinates of the functions in different modes of listening, because cocos2d is the framework of OpenGL, so coordinate transformation is needed.
+ (Cgpoint) Locationfromtouches: (nsset*) touches {return [self locationfromtouch:[touches anyobject]]; } + (Cgpoint) Locationfromtouch: (uitouch*) Touch {cgpoint touchlocation = [Touch locationinview: [Touch view]] ; return [[Ccdirector Shareddirector] converttogl:touchlocation]; }
Two methods can see the difference, one is Uitouch, one is Nsset, one is a single monitor, one is the distribution of listening;