2009-11-21 4 views
0

Я не уверен, что способ, применяемый в touchhesBegan, может быть применен также в ccTouchesBegan или других обратных вызовах. Например, у меня есть некоторый код:touchsBegan конвертирует в 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 -в показывают, что событие было обработано, и прекратить пересылку событие следующему обработчику в цепочке, или

  • kEventIgnored - продолжить пересылку даже следующему обработчику в цепи

Смежные вопросы