我正试图让元素在cercle的边缘移动.
>我已经在屏幕中间创建并定位了一个cercle:
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)
宇宙飞船的第一次旋转(见下图)完全遵循圆的边缘,但第二次迭代改变了宇宙飞船的位置并将其移出屏幕边界.
这是正常的还是我做错了什么?
谢谢.
+ follow:duration:产生与
follow:asOffset:orientToPath:duration:相同的效果,asOffset和orientToPath参数设置为true.
原文链接:https://www.f2er.com/swift/319402.html关于docs中的asOffset参数:
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.
所以,你应该明确地将它设置为false:
let circularMove = SKAction.follow(circle.CGPath,asOffset: false,orientToPath: true,duration: 5)