Я тоже пытался сделать эту работу, но я нашел более простой, а также лучший способ управления.
так, например, если вы хотите обнаружить движение влево, я бы такследующие.
Объявите две переменные в интерфейсе вашего класса
CGPoint firstTouch;
CGPoint lastTouch;
В методе init реализации вашего класса enable прикосновения
self.isTouchEnabled = YES;
3.Добавьте эти методы в ваш класс
-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSSet *allTouches = [event allTouches];
UITouch * touch = [[allTouches allObjects] objectAtIndex:0];
CGPoint location = [touch locationInView: [touch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
//Swipe Detection Part 1
firstTouch = location;
}
-(void) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
NSSet *allTouches = [event allTouches];
UITouch * touch = [[allTouches allObjects] objectAtIndex:0];
CGPoint location = [touch locationInView: [touch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
//Swipe Detection Part 2
lastTouch = location;
//Minimum length of the swipe
float swipeLength = ccpDistance(firstTouch, lastTouch);
//Check if the swipe is a left swipe and long enough
if (firstTouch.x > lastTouch.x && swipeLength > 60) {
[self doStuff];
}
}
, метод "doStuff" вызывается, если произошел левый удар.