включение мультитач ... нужна помощь в сохранении 2-го касания - PullRequest
0 голосов
/ 22 апреля 2011

нужно иметь возможность хранить 2 касания, как я это делаю, я не знаю ...

так я делаю одно касание

- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

/////checks whether the screen has been touched and stores its location and converts the coordinates to be avaible for use////
UITouch* myTouch = [touches anyObject];
CGPoint locationLeft = [myTouch locationInView: [myTouch view]];
locationLeft = [[CCDirector sharedDirector]convertToGL:locationLeft];

как мне сохранить второе касание?

Заранее спасибо

Ответы [ 2 ]

2 голосов
/ 22 апреля 2011

Вы должны использовать ccTouchBegan (обратите внимание на единичное «касание» вместо «касания»), когда вам нужно обрабатывать мульти-касания.(IMO люди должны просто отказаться от ccTouchesBegan / Moved / Ended и просто использовать ccTouchBegan / Moved / Ended).

Каждый из ccTouchBegan / Moved / Ended вызывается для каждого касания, что означает, что вы можете легко различать несколько касаний.Пример:

- (void)registerWithTouchDispatcher {
   [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:1 swallowsTouches:YES]; 
}

- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
   if (self.firstTouch == nil) {
      // we got the first touch
      self.firstTouch = touch;
   }
   else if (self.secondTouch == nil) {
      // we got the second touch
      self.secondTouch = touch;
   }
   // return YES to consume the touch (otherwise it'll cascade down the layers)
   return YES;
}

- (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event {
   if (touch == self.firstTouch) {
      // we got the first touch
      // do stuff
   }
   else if (touch == self.secondTouch) {
      // we got the second touch
      // do stuff
   }
}

- (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event {
   if (touch == self.firstTouch) {
      // first touch ended so remove both touches
      self.firstTouch = nil;
      self.secondTouch = nil;
   }
   else if (touch == self.secondTouch) {
      // second touch ended so remove touch only
      self.secondTouch = nil;
   }
}
0 голосов
/ 22 апреля 2011

Вы пробовали повторять такие прикосновения, как это?

for (UITouch *touch in touches){
    CGPoint location = [touch locationInView:[touch view]];
    location = [[CCDirector sharedDirector] convertToGL:location];
    location = [self convertToNodeSpace:location];
...