touchesBegan转换为c TouchesBegan?

时间:2009-11-21 04:24:08

标签: objective-c cocoa-touch

我不确定在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

1 个答案:

答案 0 :(得分:0)

对于ccTouches *,相同的代码应该是可重用的。只需要另外一件事,就是返回

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

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