2012-08-05 69 views
0

我有一个pong游戏,我用手指移动桨。有一根手指时,一切顺利。但是当我想要控制两名选手,两名选手时,一名选手的动作很好,但另一名选手动作非常迟缓。当第二个桨开始移动时,我的第一个桨停止。我该如何让这两种动作顺畅且反应灵敏?多点触控和ccTouchesMoved,laggy移动

我在我的导演中启用了多点触控功能。

这里是我的触动代码:

- (void) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    UITouch *myTouch = [touches anyObject]; 
    CGPoint location = [myTouch locationInView:[myTouch view]]; 
    location = [[CCDirector sharedDirector] convertToGL:location]; 
    CGRect leftTouchZone = CGRectMake(0, 0, 50, 320); 
    CGRect rightTouchZone = CGRectMake(430, 0, 50, 320); 

    if (CGRectContainsPoint(leftTouchZone, location)) 
    { 
     CGPoint tempLoc = location; 
     tempLoc.x = paddle1.position.x; 
     paddle1.position = tempLoc; 
    } 

    if (CGRectContainsPoint(rightTouchZone, location)) 
    { 
     CGPoint tempLoc = location; 
     tempLoc.x = paddle2.position.x; 
     paddle2.position = tempLoc; 
    } 

回答

1

不应该您完成所有的触摸看对象,而不是仅仅抓住任何对象?如果您同时移动两次触摸,则只有一个触摸移动事件。

- (void) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    for (UITouch* myTouch in touches) 
    { 
     CGPoint location = [myTouch locationInView:[myTouch view]]; 
     location = [[CCDirector sharedDirector] convertToGL:location]; 
     CGRect leftTouchZone = CGRectMake(0, 0, 50, 320); 
     CGRect rightTouchZone = CGRectMake(430, 0, 50, 320); 

     if (CGRectContainsPoint(leftTouchZone, location)) 
     { 
      CGPoint tempLoc = location; 
      tempLoc.x = paddle1.position.x; 
      paddle1.position = tempLoc; 
     } 

     if (CGRectContainsPoint(rightTouchZone, location)) 
     { 
      CGPoint tempLoc = location; 
      tempLoc.x = paddle2.position.x; 
      paddle2.position = tempLoc; 
     } 
    } 
+0

工作!非常感谢! – Dvole 2012-08-05 16:16:23