我不完全理解这一点,我正在尝试使用默认模板设置触摸处理,我所做的唯一区别是我将如何处理触摸委托给实现协议的类。问题是唯一kTouchPhase
有效的是kTouchPhaseCancelled
.
-(void) update:(ccTime)delta
{
if ([input isAnyTouchOnNode:self touchPhase:KKTouchPhaseAny])
{
CCLOG(@"Touch: beg=%d mov=%d sta=%d end=%d can=%d",
[input isAnyTouchOnNode:self touchPhase:KKTouchPhaseBegan],
[input isAnyTouchOnNode:self touchPhase:KKTouchPhaseMoved],
[input isAnyTouchOnNode:self touchPhase:KKTouchPhaseStationary],
[input isAnyTouchOnNode:self touchPhase:KKTouchPhaseEnded],
[input isAnyTouchOnNode:self touchPhase:KKTouchPhaseCancelled]);
}
CCDirector* director = [CCDirector sharedDirector];
if (director.currentPlatformIsIOS)
{
[self gestureRecognition]; // Calls method pasted bellow
if ([KKInput sharedInput].anyTouchEndedThisFrame)
{
CCLOG(@"anyTouchEndedThisFrame");
}
}
.->
-(void) gestureRecognition
{
NSAssert(self.delegate != nil, @"Delegate must be non-nil");
if (input.gestureTapRecognizedThisFrame)
{
[self.delegate moveObjectToNewPosition:input];
}
然后实现协议的委托决定在其中做什么moveObjectToNewPosition:
-(void) moveObjectToNewPosition:(KKInput *)input
{
//KKInput *input = [KKInput sharedInput];
CGSize screenSize = [[CCDirector sharedDirector] winSize];
CGPoint touchLocation = [input locationOfAnyTouchInPhase:KKTouchPhaseBegan];
[self touchesBegan:touchLocation];
}
- (void)touchesBegan: (CGPoint)touchLocation
{
CCLOG(@"x: %f y: %f", touchLocation.x, touchLocation.y);
}
但是给我坐标的唯一触摸阶段是KKTouchPhaseCancelled
或KKTouchPhaseAny
......这里发生了什么?