【问题标题】:Handling CCSprites with Multiple Touch使用多点触控处理 CCSprite
【发布时间】:2016-04-27 16:27:57
【问题描述】:

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

任何帮助将不胜感激..

这是我的代码:

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


    }

【问题讨论】:

    标签: cocos2d-iphone ccsprite spritebuilder


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2012-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多