I am trying to make an element move along the edge of a circle.
- I created and placed a circle in the center of the screen:
var base = SKShapeNode(circleOfRadius: 200 ) // Size of Circle base.position = CGPointMake(frame.midX, frame.midY) base.strokeColor = SKColor.blackColor() base.glowWidth = 1.0 base.fillColor = UIColor(hue:1, saturation:0.76, brightness:0.94, alpha:1) base.zPosition = 0 self.addChild(base)
- Then I created another sprite and added an action to it:
main = SKSpriteNode(imageNamed:"Spaceship") main.xScale = 0.15 main.yScale = 0.15 main.zPosition = 1 let circle = UIBezierPath(roundedRect: CGRectMake((self.frame.width/2) - 200, CGRectGetMidY(self.frame) - 200,400, 400), cornerRadius: 200) let circularMove = SKAction.followPath(circle.CGPath, duration: 5.0) main.runAction(SKAction.repeatAction(circularMove,count: 2)) self.addChild(main)
The first rotation (see image below) of the spacecraft goes exactly along the edges of the circle, but the second iteration changes the position of the spacecraft and moves it off the screen. Is this normal or am I doing something wrong?
Thanks.

swift sprite-kit
Sahbi Belgacem
source share