如何在Cocos2d 3.2中找到多个触摸的位置?

时间:2015-08-17 16:52:03

标签: cocos2d-iphone

我希望在CGPoint中获取两个手指的位置。

我怎样才能从CCTouchEvent那里得到它?

我到目前为止已尝试过:

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

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

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

    }

}

2 个答案:

答案 0 :(得分:1)

通过枚举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);


 }

}

答案 1 :(得分:0)

你需要尝试这个: 第一个参数不再是CCTouch,它需要是一个集合所以

-(void)ccTouchesBegan:(NSSet *)touches withEvent:(CCTouchEvent *)event{
    for(CCTouch* touch in touches){
        [touch getLocation];
    }
}