I\'m making a sprite to orbit a point and for that I made a path that is followed by that sprite:
let dx1 = base1!.position.x - self.frame.width/2
let dy
A straightforward way to rotate a sprite about a point (i.e., orbit) is to create a container node, add a sprite to the node at an offset (relative to the container's center), and rotate the container node. Here's an example of how to do that:
class GameScene: SKScene {
let sprite = SKSpriteNode(imageNamed:"Spaceship")
let node = SKNode()
override func didMove(to view: SKView) {
sprite.xScale = 0.125
sprite.yScale = 0.125
sprite.position = CGPoint (x:100, y:0)
node.addChild(sprite)
addChild(node)
let action = SKAction.rotate(byAngle:CGFloat.pi, duration:5)
node.run(SKAction.repeatForever(action), withKey:"orbit")
}
override func touchesBegan(_ touches: Set, with event: UIEvent?) {
if let action = node.action(forKey: "orbit") {
// Reverse the rotation direction
node.removeAction(forKey:"orbit")
node.run(SKAction.repeatForever(action.reversed()),withKey:"orbit")
// Flip the sprite vertically
sprite.yScale = -sprite.yScale
}
}
}