我希望能够拿起SKSpriteNode并实际上用手指“悬挂”它。我一直在尝试SKPhysicsJointPin,但似乎并没有达到预期的效果。
这是我正在使用的代码:
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
if let touch = touches.first {
let location = touch.location(in: self)
if !BeingMoved {
BeingMoved = true
TempDragNode.name = "TempDragNode"
TempDragNode.size = CGSize(width: 44, height: 44)
TempDragNode.physicsBody = SKPhysicsBody(circleOfRadius: 44)
TempDragNode.physicsBody?.affectedByGravity = false
addChild(TempDragNode)
TempDragNode.physicsBody?.allowsRotation = false
let PositionX = CGPoint(x: TempDragNode.position.x, y: TempDragNode.position.y+(TempDragNode.frame.height/2))
let PinJoint = SKPhysicsJointPin.joint(withBodyA: (childNode(withName: "Nutty")?.physicsBody)!, bodyB: TempDragNode.physicsBody!, anchor: PositionX)
scene?.physicsWorld.add(PinJoint)
}
TempDragNode.position = location
}
}