I'm trying make an element move by the edge of circle.
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)
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 spaceship follow exactly the edges of the circle but the second iteration changes the position of the spaceship and move it outside the screen bounds. Is this normal or am I doing something wrong ?
Thanks.
+ follow:duration: produce the same effect as follow:asOffset:orientToPath:duration: with both, asOffset
and orientToPath
parameters set to true
.
About asOffset parameter from the docs:
If true, the points in the path are relative offsets to the node’s starting position. If false, the points in the node are absolute coordinate values.
So, you should explicitly set it to false:
let circularMove = SKAction.follow(circle.CGPath, asOffset: false, orientToPath: true, duration: 5)
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