I've been trying to be able to alter gravity by using
override func touchesBegan(_ touches: Set<UITouch>, with event:
UIEvent?) {
self.physicsWorld.gravity = CGVector(dx: 0, dy: 0)
}
but that doesn't seem to change the gravity at all. When I use the same code in the didMove function, it works.
EDIT 1:
Here's the code for for my SKSpriteNode:
spaceship = SKSpriteNode(imageNamed: "Spaceship")
spaceship.position = CGPoint(x: self.frame.width / 2, y: self.frame.height / 2)
spaceship.setScale(0.1)
spaceship.physicsBody?.isDynamic = true
spaceship.physicsBody = SKPhysicsBody(circleOfRadius: spaceship.size.width / 2);
addChild(spaceship)
spaceship.physicsBody?.isDynamic = true
in your code is doing nothing. – SaganRitual