我正在尝试实现将改变单位移动方向的游戏控制。因此,如果我向右滑动它会向右转,如果我向下滑动它会转向向下等等。
这是 cocos2d 游戏,我正在CCNode+SFGestureRecognizers
使用UISwipeGestureRecognizer
.
现在我有下一个实现它
UISwipeGestureRecognizer *rightSwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleRightSwipe:)];
[self addGestureRecognizer:rightSwipeGestureRecognizer];
rightSwipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
rightSwipeGestureRecognizer.delegate = self;
[rightSwipeGestureRecognizer release];
UISwipeGestureRecognizer *upSwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleUpSwipe:)];
[self addGestureRecognizer:upSwipeGestureRecognizer];
upSwipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionUp;
upSwipeGestureRecognizer.delegate = self;
[upSwipeGestureRecognizer release];
UISwipeGestureRecognizer *leftSwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleLeftSwipe:)];
[self addGestureRecognizer:leftSwipeGestureRecognizer];
leftSwipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
leftSwipeGestureRecognizer.delegate = self;
[leftSwipeGestureRecognizer release];
UISwipeGestureRecognizer *downSwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleDownSwipe:)];
[self addGestureRecognizer:downSwipeGestureRecognizer];
downSwipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionDown;
downSwipeGestureRecognizer.delegate = self;
[downSwipeGestureRecognizer release];
但问题是要识别以下手势,您需要将手指从屏幕上抬起。如果您在第一次滑动后没有抬起手指,它只会识别第一次滑动。
现在:
应该如何:
最好的方法是什么?谢谢!