多人游戏如何使用多点触控

时间:2011-12-21 04:01:39

标签: ios xcode cocoa-touch multi-touch game-physics

我正在制作一款游戏,其中2人有iphone屏幕的任一侧移动他们的作品。我在使用多点触控部件时遇到了一些麻烦,多点触控设置也开启了。这是当前的代码,我需要两个用户能够同时移动,目前只有一个可以。

黄色和绿色是两个被移动的部分(仅在x轴上)

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
touch = [[event touchesForView:self.view] anyObject];
location = [touch locationInView:self.view];  
if (location.y > 230) { 
    locationYellow = location; 
    yellow.center = CGPointMake(locationYellow.x, yellow.center.y); 
}else{
    locationGreen = location;   
    if (VSModeON == YES) {
        green.center = CGPointMake(locationGreen.x, green.center.y);
    }
  }
}

1 个答案:

答案 0 :(得分:1)

touch = [[event touchesForView:self.view] anyObject]; 

这听起来像触摸的任何物体。此代码通常用于您只需要单次触摸的位置。您当前的代码一次只能处理一次。

对于多点触控,您需要分析集合[event touchesForView:self.view]中的每个触摸并采取相应措施。

类似

for (UITouch *aTouch in [event touchesForView:self.view])
{
    // Deal with each touch here...
}