I'm in the process of updating my current app, and I was wondering if there is a way to rotate a sprite node around the center? For example, Earth revolving around the Sun. I'm also using the sks file.
This is what I have:
import SpriteKit
import GameplayKit
class StartScene: SKScene {
var singleTap = SKSpriteNode()
var path = UIBezierPath()
var gameStarted = Bool()
override func didMove(to view: SKView) {
singleTap = self.childNode(withName: "single") as! SKSpriteNode
singleTap.anchorPoint = CGPoint(x: 0.5, y: 0.5)
moveCounterClockwise()
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
}
func moveCounterClockwise() {
let dx = singleTap.position.x - self.frame.midX
let dy = singleTap.position.y - self.frame.midY
let rad = atan2(dy, dx)
path = UIBezierPath(arcCenter: CGPoint(x: self.frame.midX, y: self.frame.midY), radius: 120, startAngle: rad, endAngle: rad + CGFloat(Double.pi * 4), clockwise: true)
let follow = SKAction.follow(path.cgPath, asOffset: false, orientToPath: true, speed: 60)
singleTap.run(SKAction.repeatForever(follow))
}
override func update(_ currentTime: TimeInterval) {
// Called before each frame is rendered
}
}
This code makes the sprite rotate around the center, but it also rotates the sprite itself by 90 degrees.
I have also looked at this answer, but I can't wrap my head around how to write it: https://stackoverflow.com/a/19045698/3926691
Edit: These two images are based on what I'm trying to accomplish and what is happening. It seems like the UIBezierPath is causing some sort of unwanted Z-Rotation.
Any help is welcome, and I can try to provide clarity if needed.