我正试图让元素在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.
关于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)
原文地址:https://www.jb51.cc/swift/319402.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。