2011-04-23 79 views
0

我幾乎已經完成了我的多點觸控代碼,但是我仍然遇到了另一個問題。這是在cocos2d做BTW :)多點觸控..需要iOS 4.3或更高版本的幫助

玩家對左側的DPAD和右側的按鈕,它工作正常,如果我按住了dpads的按住跳躍鍵,讓他給跑正確和跳躍。

的問題是,一旦我擡起我的手指斷跳躍鍵的所有動作停止,所以我必須擡起並再次按下我的手指向下DPAD ...

這是我cctouchesended

代碼
-(void) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 

////when the user has stopped touching the screen set the variables 
    ////back to false to stop its movement//// 

//self.myTouch = nil; 
for (UITouch *touch in touches) 
{ 
    if (moveRight == TRUE) { 
    [player stopAction:RunForward]; 

    } 
    if (moveLeft == TRUE) { 
    [player stopAction:RunBackwards]; 

    } 
    moveLeft = FALSE; 
    moveRight = FALSE; 
// jump = FALSE; 
} 



} 

回答

0

您最好將邏輯映射到2個按鈕。或者至少爲了跳躍。 與當前代碼的問題是,您不檢查,看看你擡起的手指。您可以添加支票,以便如果結束的觸摸位於屏幕的左側,則停止移動。

此外,您不需要將BOOL值與TRUE進行比較。只要做,「如果(moveRight)」。這是更好的

0

你會想保持參照HASH(touch.hash)並保存CCTouchesBegan

那麼你現在(釋放)具備的功能,你檢查哪個哈希已被釋放。

這樣:

  1. 在ccTouchesBegan功能檢查你按下哪個按鈕

    如果(CCRectContainsPoint(sprite1.boundingbox,touchlocation)){ rightSideButtonHash = touch.hash; )

在發行

您檢查touch.hash對rightSideButtonHash,你知道,如果它是聯繫!