如何在 Cocos2d 3.2 中找到多个触摸的位置?
How to find location of multiple touches in Cocos2d 3.2?
我想在 CGPoint 中获取两根手指的位置。
我如何从 CCTouchEvent 中获取它?
到目前为止我已经尝试过:
-(void)touchMoved:(CCTouch *)touch withEvent:(CCTouchEvent *)event{
if ([[event allTouches] count]==2) {
NSLog(@"Detected");
NSLog(@"event: %@",event.allTouches);
}
}
你需要试试这个:
第一个参数不再是 CCTouch 它需要是一个集合所以
-(void)ccTouchesBegan:(NSSet *)touches withEvent:(CCTouchEvent *)event{
for(CCTouch* touch in touches){
[touch getLocation];
}
}
通过枚举 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);
}
}
我想在 CGPoint 中获取两根手指的位置。
我如何从 CCTouchEvent 中获取它?
到目前为止我已经尝试过:
-(void)touchMoved:(CCTouch *)touch withEvent:(CCTouchEvent *)event{
if ([[event allTouches] count]==2) {
NSLog(@"Detected");
NSLog(@"event: %@",event.allTouches);
}
}
你需要试试这个: 第一个参数不再是 CCTouch 它需要是一个集合所以
-(void)ccTouchesBegan:(NSSet *)touches withEvent:(CCTouchEvent *)event{
for(CCTouch* touch in touches){
[touch getLocation];
}
}
通过枚举 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);
}
}