如果用户向左或向右滑动,我想要旋转SKSpriteNode
。
我可以使用UIGestureRecognizer
还是有另一种方法来解决它?
答案 0 :(得分:0)
最简单的方法是向SKView添加两个UISwipeGestureRecognizer(每个方向一个)。
如果你想处理更慢的手指动作,你需要用UIPanGestureRecognizer替换它们。
答案 1 :(得分:0)
在你的场景中,像这样实施didMoveToView:(SKView*)view
- (void)didMoveToView:(SKView *)view {
self.leftSwipeRecognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(leftSwipe)];
self.leftSwipeRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
[view addGestureRecognizer:self.leftSwipeRecognizer];
self.rightSwipeRecognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(rightSwipe)];
self.rightSwipeRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
[view addGestureRecognizer:self.rightSwipeRecognizer];
}
- (void)rightSwipe {
//whatever angle and duration you need here (angle in radians)
NSTimeInterval duration = 0;
CGFloat angle = 0;
[self enumerateChildNodesWithName:nodeIdentifier usingBlock:^(SKNode *node, BOOL *stop) {
[node runAction:[SKAction rotateByAngle:angle duration:duration]];
}];
}
name
的{{1}}属性。