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

问题描述:

我正在做一个游戏,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); 
    } 
    } 
} 
+0

您还没有实际说的是什么问题。 – jrturton 2011-12-21 07:02:08

+0

对不起,我没有说清楚,问题是,这是行不通的。只有一个桨可以一次 – Jordan 2011-12-21 07:38:51

+0

@Jordan布朗被感动:“问题是,它不工作”是不清楚超越不清楚。这是最好的避免说类似的事情和*只是解释如何*它不工作... – BoltClock 2011-12-21 11:56:33

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

这需要的,因为它听起来像它会,从触摸的任何对象。此代码通常用于您只需要单点触摸的情况。您目前的代码一次只能处理一次触摸。

对于多点触控,你需要分析该组[event touchesForView:self.view]每个触摸并采取相应的行动。

因此,像

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

感谢你这个固定的问题 – Jordan 2011-12-21 09:32:00