2013-05-13 23 views
0

我不完全理解這一點,我試圖設置使用默認模板的觸摸處理,唯一的區別是我委託如何處理觸摸類的實現協議。問題是,唯一可用的kTouchPhasekTouchPhaseCancelledKobold2d:KKInput觸摸處理使用touchPhases

-(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); 
} 

但唯一的觸摸階段,讓我做協調是KKTouchPhaseCancelledKKTouchPhaseAny ...這裏發生了什麼?

回答

0

手勢識別器捕捉觸摸事件,特別是輕拍識別器實際上會檢測到任何觸摸(大部分觸摸都是輕敲),因此您看不到任何其他觸摸事件(階段)但取消。

要解決此問題,請使用輕擊手勢的位置屬性,而不是任何觸摸的位置。

+0

好吧,我把'if(input.gestureTapRecognizedThisFrame)'改爲'input.touchesAvailable'。現在我在'[self touchesBegan:[input locationOfAnyTouchInPhase:KKTouchPhaseBegan]]中獲取touchPhaseBegan;'但是如果我對KKTouchPhaseMoved和KKTouchPhaseEnded執行相同操作,則結果不穩定 – 2013-05-13 08:45:06