2012-01-19 55 views
1

我試圖移動精靈使用周圍和UITouch我需要在多點觸控模式,因爲我有一個按鈕,我還需要而我走動我的精靈打。CC UITouches忽略第二觸摸

的問題是,當我錯過了按鈕,我打在屏幕上與我的其他手指的第二手指變成觸摸開始引起我的精靈跳位置。 任何工作。我嘗試在自己的班級中按按鈕,但這並沒有幫助。 我不只是把所有的代碼移動觸摸是因爲我正在計算從觸摸開始的偏移量。

-(void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ 
    NSSet *allTouches = [event allTouches]; 
    switch ([allTouches count]) { 
     case 1:{ 
      NSLog(@"moving touch 1");}break; 

所以,現在所發生的事情是,當我在屏幕上 檢測移動1移動我的手指,但一旦我把第二根手指停止移動1 我不希望它停止運行1

回答

0

在你-touchesBegan:方法,你測試觸摸點,看看它的圖像裏面?

0

把條件對兩個按鈕的觸摸,不包括任何其他情況下存在,這將是所有以避免其他觸摸。

像:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ 
    NSSet *allTouches = [event allTouches]; 

    switch ([allTouches count]) { 
     case 1: { 
      CGPoint pos = [[[allTouches allObjects] objectAtIndex:0] locationInView:self]; 
      // code here for single touch. 


     } break; 
     case 2: { 
      //get out two fingers 
      UITouch *touch1 = [[allTouches allObjects] objectAtIndex:0]; 
      UITouch *touch2 = [[allTouches allObjects] objectAtIndex:1]; 
      // code here for multi touch 

     } break; 

    } 


} 

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ 
    NSSet *allTouches = [event allTouches]; 

    switch ([allTouches count]) 
    { 
     case 1: { //Move 
      //Single touch 


     } break; 
     case 2: { //Zoom 
      //multi touch 

      UITouch *touch1 = [[allTouches allObjects] objectAtIndex:0]; 
      UITouch *touch2 = [[allTouches allObjects] objectAtIndex:1]; 

      // Code according to you 


     } break; 

    } 

} 

希望這會有所幫助。

+0

現在測試出來thanx的迴應 – michael

+0

這是一個很大的幫助,但沒有解決我的問題,請檢查我的代碼頂部 – michael

+0

你必須做的是,你必須重複情況2的代碼。所以,如果你觸摸兩個手指,代碼切換到第二個案例,但它會發現情況1碼too.It會更好,如果你做外殼的方法1. – Haroon