gpt4 book ai didi

swift - 使用贝塞尔路径 Action 时, Action 使形状节点消失

转载 作者:行者123 更新时间:2023-11-30 10:18:40 24 4
gpt4 key购买 nike

我正在尝试沿着 UIBezierPath 移动 SKShapeNode。这是我到目前为止的代码:

// Set up the circle track
let circleTrack = UIBezierPath(roundedRect: CGRectMake(screenWidth/2, screenHeight/2, screenWidth/3, screenWidth/3), cornerRadius: 100)
let shapeTrack = SKShapeNode(path: circleTrack.CGPath, centered: true)
shapeTrack.position = CGPointMake(screenWidth/2, screenHeight/2)
shapeTrack.strokeColor = SKColor.whiteColor()
self.addChild(shapeTrack)

// Create the ball
let circle = SKShapeNode(circleOfRadius: 15)
circle.position = CGPointMake(screenWidth/2, screenHeight/2)
circle.fillColor = SKColor.whiteColor()
self.addChild(circle)

//Move the circle
circle.runAction(SKAction.repeatActionForever(SKAction.followPath(circleTrack.CGPath, speed: 3.0)))

所有操作所做的就是使形状节点消失。我怎样才能让圆永远沿着贝塞尔路径移动?

最佳答案

您将贝塞尔曲线路径circleTrack 放置在一个位置,并将 shapeTrack 放置在另一位置。 circleTrack 的原点位于 (screenWidth/2,screenHeight/2),shapeTrack 的中心位于 (screenWidth/2,screenHeight/2) >。 shapeTrack.positionSKShapeNode 中心的位置。尝试以下代码。

let screenWidth = size.width
let screenHeight = size.height

let trackWidth = screenWidth/3

let circleTrack = UIBezierPath(roundedRect: CGRectMake(screenWidth/2 - trackWidth/2, screenHeight/2 - trackWidth/2, trackWidth, trackWidth), cornerRadius: 100)
let shapeTrack = SKShapeNode(path: circleTrack.CGPath, centered: true)
shapeTrack.position = CGPointMake(screenWidth/2, screenHeight/2)
shapeTrack.strokeColor = UIColor.whiteColor()
self.addChild(shapeTrack)

// Create the ball
let circle = SKShapeNode(circleOfRadius: 15)
circle.fillColor = UIColor.whiteColor()
self.addChild(circle)

let followPath = SKAction.followPath(circleTrack.CGPath, asOffset: false, orientToPath: false, speed: 200.0)

//Move the circle
circle.runAction(SKAction.repeatActionForever(followPath))

关于swift - 使用贝塞尔路径 Action 时, Action 使形状节点消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28619856/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com