加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

swift – Sprite-kit:在圆形路径中移动元素

发布时间:2020-12-14 05:30:16 所属栏目:百科 来源:网络整理
导读:我正试图让元素在cercle的边缘移动. 我已经在屏幕中间创建并定位了一个cercle: var base = SKShapeNode(circleOfRadius: 200 ) // Size of Circlebase.position = CGPointMake(frame.midX,frame.midY) base.strokeColor = SKColor.blackColor()base.glowWid
我正试图让元素在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)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读