当我用我的代码在这个场景中滚动时,看起来非常奇怪。在你放手之前,一切都会很快跳起来。有没有更好的方法呢?
var lastTouch: CGPoint!
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
let touch : UITouch = touches.first!
lastTouch = touch.locationInNode(self)
}
override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
let touch : UITouch = touches.first!
let touchLocation : CGPoint = touch .locationInNode(self)
self.camera!.position = CGPointMake(self.camera!.position.x + (lastTouch!.x - touchLocation.x), self.camera!.position.y + (lastTouch!.y - touchLocation.y))
lastTouch = touchLocation;
}
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
let touch : UITouch = touches.first!
let touchLocation : CGPoint = touch .locationInNode(self)
self.camera!.position = CGPointMake(self.camera!.position.x + (lastTouch!.x - touchLocation.x), self.camera!.position.y + (lastTouch!.y - touchLocation.y))
print(touches.count)
lastTouch = touchLocation;
}
如果真的有必要,我可以上传gif /视频。这只是SKCameraNode的一个错误,因为它是如此新颖吗?如果有人知道我做错了什么我会喜欢听。谢谢!
答案 0 :(得分:1)
我找到了答案,因为这是一个非常简单的错误。当摄像机节点移动时,您触摸的位置也会移动。我创建了一个与摄像机一起移动的节点,并获取该节点中触摸的位置。