我在SKScene中有一个节点,按照用户的触摸移动。基本上,这个角色也应该试图跟随用户的手指(假设手指在屏幕上)。我现在已经实现了,它工作正常:检测Sprite套件中的长时间触摸
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
let touch = touches.first as! UITouch
player.runAction(SKAction.moveTo(touch.locationInNode(self), duration: 1))
}
override func touchesMoved(touches: Set<NSObject>, withEvent event: UIEvent) {
let touch = touches.first as! UITouch
player.runAction(SKAction.moveTo(touch.locationInNode(self), duration: 1))
}
override func touchesCancelled(touches: Set<NSObject>!, withEvent event: UIEvent!) {
player.removeAllActions()
}
override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
player.removeAllActions()
}
但是,问题是,如果用户握住他/她的手指在手机上。 touchesBegan只被调用一次,那就是当龙头开始的时候,而不是它被保持的时候。我希望玩家角色不断尝试触及手指。
我将相机居中在节点上,所以节点应该只接触手指的唯一时间是用户将手指放在节点上(即与节点相同的位置)。因此,在我运行SKAction来移动节点后,触摸无效,因为它位于旧位置。
我该怎么做?
这就是我最终做的事情,虽然我想要的工作多一点,但工作得很好。 – Aaron