使用多点触控处理CCSprites

时间:2016-01-21 12:14:57

标签: cocos2d-iphone ccsprite spritebuilder

我有一个或多个存储在数组中的精灵。我想要的是用多个手指在屏幕周围拖动这些精灵。即(多次触摸) 谁能告诉我怎么做?

任何帮助将不胜感激..

这是我的代码:

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


    }

1 个答案:

答案 0 :(得分:0)

如果我理解正确你想在屏幕上说两根手指,每个都要移动1个精灵?我想你有一个数组中的图像,所以得到每个触摸的位置,如果每个触摸都在精灵上,那么你知道哪个精灵在哪个精灵上。

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

如果fingerOne触及了索引0处的精灵,那么你可以将其移动到与fingerOne移动相同的量,对于fingerTwo和sprite在索引1处也是如此。