谁能告诉我为什么当我尝试对这样的节点施加冲动时它会消失?
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
let touch:UITouch = touches.first! as UITouch
startPoint = touch.location(in: view)
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
defer {
startPoint = nil
}
guard touches.count == 1, let startPoint = startPoint else {
return
}
if let touch = touches.first {
let endPoint = touch.location(in: view)
//Calculate your vector from the delta and what not here
direction = CGVector(dx: endPoint.x - startPoint.x, dy: endPoint.y - startPoint.y)
L1Ball.physicsBody?.applyImpulse(CGVector(dx: direction.dx.hashValue, dy: direction.dy.hashValue))
}
}
我认为这与我使用 hashValue 的方式有关。我不知道从 CGVector 方向获取值的另一种方法。如果我尝试将方向本身用作脉冲矢量,它就会崩溃。有什么见解吗?谢谢!