2009-11-21 5 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]; 
    } 

} 

같은 코드가 어떻게 * 동일한 코드가 ccTouches 재사용해야 ccTouchesBegan

답변

0

로 변환해야하는 경우 : 예를 들어 나는 몇 가지 코드가 있습니다. 그냥 하나의 추가 일은 중 하나

  • 가 -to 이벤트가 처리되었음을 표시하고 체인의 다음 핸들러에 이벤트를 전달을 중지하거나

  • kEventHandled 반환되는 필요하다

    kEventIgnored - 체인의 다음 핸들러로도 계속 전달합니다.

관련 문제