我一直在试验 UIGestureRecognizers
和新的 SKScene/SKNode's
在 SpriteKit
。我有一个问题,我接近修复它但我对一件事感到困惑。基本上,我有一个平移手势识别器,允许用户在屏幕上拖动精灵。
我遇到的唯一问题是,实际初始化平移手势需要一次点击,然后只有在SECOND上点击才能正常工作。我想这是因为我的平移手势已经初始化了 touchesBegan
。但是,自从在SKScene中初始化它以后,我不知道还有什么地方可以使用它 initWithSize
方法停止手势识别器实际工作。
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
if (!self.pan) {
self.pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(dragPlayer:)];
self.pan.minimumNumberOfTouches = 1;
self.pan.delegate = self;
[self.view addGestureRecognizer:self.pan];
}
}
-(void)dragPlayer: (UIPanGestureRecognizer *)gesture {
CGPoint trans = [gesture translationInView:self.view];
SKAction *moveAction = [SKAction moveByX:trans.x y:-trans.y duration:0];
[self.player runAction:move];
[gesture setTranslation:CGPointMake(0, 0) inView:self.view];
}