I tried to create an object rotating outside the circle, but it turns it inside the circle.
This is what I want to do (my character):
func moveClockWise() {
var dx = Character.position.x - self.frame.width / 2
var dy = Character.position.y - self.frame.height / 2
var rad = atan2(dy, dx)
Path = UIBezierPath(arcCenter: CGPoint(x: self.frame.width / 2, y: self.frame.height / 2), radius: 150, startAngle: rad, endAngle: rad + CGFloat(M_PI * 4), clockwise: true)
let follow = SKAction.followPath(Path.CGPath, asOffset: false, orientToPath: true, speed: 200)
Character.runAction(SKAction.repeatActionForever(follow))
}
but this what happened :

I'm not going about it the exact way you are.. but this is what i came up with. just copy paste the code and try it out :)

class GameScene: SKScene {
let sprite = SKSpriteNode(color: SKColor.redColor(), size: CGSize(width: 20, height: 30))
let circleRadius = CGFloat(100)
var angleRelatedToCircle = CGFloat(0)
let rotationSpeed = CGFloat(0.01)
override func didMoveToView(view: SKView) {
let topOfSprite = SKSpriteNode(color: SKColor.blueColor(), size: CGSize(width: 20, height: 2))
topOfSprite.position.y = sprite.size.height
sprite.addChild(topOfSprite)
sprite.anchorPoint.y = 0
sprite.zRotation = CGFloat(-M_PI_2)
let circle = SKShapeNode(circleOfRadius: circleRadius)
circle.fillColor = SKColor.whiteColor()
circle.position = CGPoint(x: self.size.width/2, y: self.size.height/2)
self.addChild(circle)
circle.addChild(sprite)
sprite.position.y += circleRadius
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
sprite.zRotation += CGFloat(M_PI)
}
override func update(currentTime: NSTimeInterval) {
angleRelatedToCircle -= rotationSpeed
sprite.zRotation -= rotationSpeed
sprite.position.x = circleRadius * cos(angleRelatedToCircle)
sprite.position.y = circleRadius * sin(angleRelatedToCircle)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With