2009-11-21 24 views
0

我不确定在touchesBegan中应用的方式是否也可以应用于ccTouchesBegan或其他触摸回调。例如,我有一些代码:touchesBegan转换为ccTouchesBegan?

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    NSUInteger numTaps = [[touches anyObject] tapCount]; 
    touchPhaseText.text = @"Phase: Touches began"; 
    touchInfoText.text = @""; 
    if(numTaps >= 2) { 
     touchInfoText.text = [NSString stringWithFormat:@"%d taps",numTaps]; 
     if ((numTaps == 2) && piecesOnTop) { 
      // A double tap positions the three pieces in a diagonal. 
      // The user will want to double tap when two or more pieces are on top of each other 
      if (firstPieceView.center.x == secondPieceView.center.x) 
       secondPieceView.center = CGPointMake(firstPieceView.center.x - 50, firstPieceView.center.y - 50);  
      if (firstPieceView.center.x == thirdPieceView.center.x) 
       thirdPieceView.center = CGPointMake(firstPieceView.center.x + 50, firstPieceView.center.y + 50); 
      if (secondPieceView.center.x == thirdPieceView.center.x) 
       thirdPieceView.center = CGPointMake(secondPieceView.center.x + 50, secondPieceView.center.y + 50); 
      touchInstructionsText.text = @""; 
     } 
    } else { 
     touchTrackingText.text = @""; 
    } 
    // Enumerate through all the touch objects. 
    NSUInteger touchCount = 0; 
    for (UITouch *touch in touches) { 
     // Send to the dispatch method, which will make sure the appropriate subview is acted upon 
     [self dispatchFirstTouchAtPoint:[touch locationInView:self] forEvent:nil]; 
     touchCount++; 
    } 
} 
// Checks to see which view, or views, the point is in and then calls a method to perform the opening animation, 
// which makes the piece slightly larger, as if it is being picked up by the user. 
-(void)dispatchFirstTouchAtPoint:(CGPoint)touchPoint forEvent:(UIEvent *)event 
{ 
    if (CGRectContainsPoint([firstPieceView frame], touchPoint)) { 
     [self animateFirstTouchAtPoint:touchPoint forView:firstPieceView]; 
    } 
    if (CGRectContainsPoint([secondPieceView frame], touchPoint)) { 
     [self animateFirstTouchAtPoint:touchPoint forView:secondPieceView]; 
    } 
    if (CGRectContainsPoint([thirdPieceView frame], touchPoint)) { 
     [self animateFirstTouchAtPoint:touchPoint forView:thirdPieceView]; 
    } 

} 

如果这样的代码应该怎么将它转换为ccTouchesBegan

回答

0

相同的代码应该是可重复使用的ccTouches *。只是一个附加的东西是必需的,这是返回一个

  • kEventHandled -to表明该事件已被处理,并停止将事件转发到链中的下一个处理程序,或

  • kEventIgnored - 继续转发至链中的下一个处理程序