2016-01-21 124 views
0

我有一個或多個存儲在數組中的精靈。我想要的是用多個手指在屏幕上拖動這些精靈。即(多點觸摸) 任何人都可以告訴我該怎麼做?使用多點觸控處理CCSprites

任何幫助將不勝感激..

這裏是我的代碼:

-(void)touchBegan:(CCTouch *)touch withEvent:(CCTouchEvent *)event 
{ 

    CGPoint location = [touch locationInNode:self]; 

    selectedSprite.paused = YES; 

    [self selectSpriteFromTouch:location]; 
    //this is where i get sprite selected from i.e selectedSprite from array 


} 
-(void)touchMoved:(CCTouch *)touch withEvent:(CCTouchEvent *)event 
{ 

    selectedSprite.position = [touch locationInNode:self]; 


    } 

-(void)touchEnded:(CCTouch *)touch withEvent:(CCTouchEvent *)event 
{ 

    selectedSprite.paused = NO; 
    selectedSprite.position = [touch locationInNode:self]; 

    selectedSprite = nil; 



    } 


    -(void)touchCancelled:(CCTouch *)touch withEvent:(CCTouchEvent *)event 
    { 

    selectedSprite.paused = NO; 
    selectedSprite = nil; 


    } 

回答

0

如果我理解正確的話,你想講兩個手指在屏幕上,每移動1個精靈?我想你有一個數組中的圖像,以獲得每個觸摸的位置,如果每個觸摸都在一個精靈上,那麼你知道哪個精靈是哪個觸摸。

CGPoint fingerOne = [event.allTouches.allValues[0] locationInWorld]; 
CGPoint fingerTwo = [event.allTouches.allValues[1] locationInWorld]; 

如果子畫面在索引0,通過fingerOne觸摸,則可以通過將相同量的移動時fingerOne索引1處

動議同樣地,對於fingerTwo和子畫面