你好,我正在尝试在我的Sprite Kit游戏中使用手势识别器,我编写了以下代码:
@interface GameScene() <UIGestureRecognizerDelegate>{
UISwipeGestureRecognizer *swipeGestureLeft;
ISwipeGestureRecognizer *swipeGestureRight;
}
@end
@implementation GameScene
-(id)initWithSize:(CGSize)size{
if(self = [ super initWithSize:size]){
}
return self;
}
-(void)didMoveToView:(SKView *)view{
swipeGestureLeft = [[UIGestureRecognizer alloc]initWithTarget:self action:@selector(swipeLeft)];
[swipeGestureLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
[view addGestureRecognizer:swipeGestureLeft];
swipeGestureRight = [[UIGestureRecognizer alloc]initWithTarget:self action:@selector(swipeRight)];
[swipeGestureRight setDirection:UISwipeGestureRecognizerDirectionRight];
[view addGestureRecognizer:swipeGestureRight];
}
- ( void ) willMoveFromView: (SKView *) view {
[view removeGestureRecognizer: swipeGestureLeft ];
[view removeGestureRecognizer: swipeGestureRight];
}
-(void)swipeLeft:(UISwipeGestureRecognizer*) recognizer{
NSLog@"Left"'
}
-(void)swipeRight:(UISwipeGestureRecognizer*) recognizer{
NSLog@"Right"'
}
@end
我认为一切都好,但是我的手势不起作用,而且我没有错误信息。是否还有什么我应该在我的应用程序中添加,或者我应该在我的视图控制器中添加一些内容?或者你们能否向我推荐一个教程,展示如何在Sprite Kit中使用手势。