我有spriteNode
我需要在SKSpriteNode
上进行滑动检测,但似乎滑动手势只能在视图上进行。有没有办法做到这一点?
SKSpriteNode *rabbit = [SKSpriteNode spriteNodeWithImageNamed:@"rabbit_img"];
UISwipeGestureRecognizer * swipeleft=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeGesture:)];
swipeleft.direction=UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeleft];
答案 0 :(得分:0)
您可以通过state
property获取滑动的起始坐标。
- (void)swipe:(UISwipeGestureRecognizer *)recognizer
{
CGPoint point = [recognizer locationInView:[recognizer view]];
if (recognizer.state == UIGestureRecognizerStateBegan)
NSLog(@"start coordinates: %@", NSStringFromCGPoint(point));
}
然后,您可以使用SKNode方法containsPoint:
将这些坐标与所需节点进行比较,以查看滑动是否来自节点。