I can\'t change the position of a SKSpriteNode by changing
self.position = newPosition;
It doesn\'t work anymore if it has a physicsBody.
I ran into a similar problem. When using SKAction
, even with duration set to 0.0 I got strange behaviours especially when two SKActions
had been triggered at the same time.
I tried setting position directly but as mentioned by others this doesn't work when using the SKPhysicsContactDelegate
.
However for me it worked to remove the node from its parent, I then set the new position, and other things I want to change, and then I add the node again to its former parent.
It's not ideal but in some cases it might help.
As an example with the SKPhysicsContactDelegate method didBegin:
func didBegin(_ contact: SKPhysicsContact) {
guard let node = contact.bodyB.node else { return }
node.removeFromParent()
node.position = CGPoint(x: 10, y: 10)
addChild(node)
}