touchesBegan converts to ccTouchesBegan?
I am not sure if the way that applied in touchesBegan can be applied as well in ccTouchesBegan or other touches call back. For example I have some code:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSUInteger numTaps = [[touches anyObject] tapCount];
touchPhaseText.text = @"Phase: Touches began";
touchInfoText.text = @"";
if(numTaps >= 开发者_如何学Python2) {
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];
}
}
If the code like this how should I convert it to ccTouchesBegan
The same code should be reusable for ccTouches*. Just one additional thing is required, which is to return either a
kEventHandled -to indicate that the event has been handled, and to stop forwarding the event to the next handler in the chain, or
kEventIgnored - continue forwarding even to the next handler in the chain
精彩评论