2012-12-22 40 views
1

我使用kobold2d的KKInput使用平移手勢識別器進行拖放操作。當iphone平放在桌面上時,它的工作原理是完美的,但如果我將手機向我傾斜,翻譯似乎完全錯誤,並且不再正常運行,實際上它似乎認爲我的iPhone是顛倒的,我認爲。KKInput panningGesture在Iphone傾斜時給出錯誤值

我做錯了什麼?

示例代碼:

if([input gesturePanBegan]) 
    { 
     for(CCSprite* item in self.View.children) 
     { 
      bool result = [input isAnyTouchOnNode:item touchPhase: KKTouchPhaseAny]; 
      if (result) 
      { 
       itemPanning = item; 
       originalPostion = item.position; 

      } 
     } 
     CCLOG(@"%f y translation %f x translation", input.gesturePanTranslation.y , input.gesturePanTranslation.x); 
     if(itemPanning != NULL) 
     { 
      [itemPanning setPosition:ccp(input.gesturePanTranslation.x + originalPostion.x, originalPostion.y)]; 
      if(input.gesturePanTranslation.x > 70) 
      { 
       [View Select: [itemPanning tag]]; 

       SelectAttackCommand * command = [SelectAttackCommand new]; 
       command.SelectedAttack = [itemPanning tag]; 

       itemPanning = NULL; 

       NOTIFY(command); 
      } 
     } 
    } 
    else if(![input gesturePanBegan] && itemPanning != NULL) 
    { 
     itemPanning = NULL; 
     [View Open]; 
    } 

回答

1

這是一個答案,但也許不是最好的之一。在KKInputGesture中,在handlePanGesture下,翻譯的值計算如下:

gesturePanTranslation = [panRecognizer translationInView:glView]; gesturePanTranslation = [self convertRelativePointToGL:gesturePanTranslation];

這裏的第二個調用根據設備的方向轉換值。這對某些場景可能沒有問題,但在我的情況下,它不是必需的,所以我評論說,現在我的翻譯值總是正確的,無論我如何傾斜iPhone。

雖然我可能在這裏錯過了一些東西,所以我不想將其標記爲答案。

+0

我已經註釋掉gesturePanTranslation - = [self convertRelativePointToGL:gesturePanTranslation]; - 它仍然不能解決我的同樣的問題......呵? – Clev3r

+0

傾斜電話仍然打破你的平移? – AwDogsGo2Heaven

+0

是的。我認爲這可能是一個問題,我如何根據平移來改變我的對象。請參閱:http://stackoverflow.com/questions/14668685/improper-iphone-orientation/14670540#14670540如果你想幫助。 – Clev3r