Search code examples
cocos2d-iphone

How to find location of multiple touches in Cocos2d 3.2?


I want to get the location of two fingers taped in view in CGPoint.

How can i get that from CCTouchEvent?

i have tried so far:

-(void)touchMoved:(CCTouch *)touch withEvent:(CCTouchEvent *)event{

    if ([[event allTouches] count]==2) {

       NSLog(@"Detected");
       NSLog(@"event: %@",event.allTouches);

    }

}

Solution

  • By enumerating the values of allTouches:

    -(void)touchMoved:(CCTouch *)touch withEvent:(CCTouchEvent *)event{
    
    if ([[event allTouches] count]==2) {
    
    
        CGPoint fingerOne = [event.allTouches.allValues[0] locationInWorld];
        CGPoint fingerTwo = [event.allTouches.allValues[1] locationInWorld];
    
        NSLog(@"fingerOne: x = %f, y = %f",fingerOne.x,fingerOne.y);
        NSLog(@"fingerTwo: x = %f, y = %f",fingerTwo.x,fingerTwo.y);
    
    
     }
    

    }