我有一个 Sprite 遵循 CGPathCreateWithEllipseInRect 描述的路径。它总是从最右边的点开始(我猜是因为默认是从角度 = 0 开始)。我如何让它从最高点开始(角度 = π/2)?我现在的代码是这样的:
let pathCenter = CGPoint(x: frame.width/2 , y: frame.height/2)
let pathDiameter = CGFloat(frame.height/4)
let path = CGPathCreateWithEllipseInRect(CGRect(origin: pathCenter, size: CGSize(width: pathDiameter * 1.5, height: pathDiameter * 0.8)), nil)
let followPath = SKAction.followPath(path, asOffset: false, orientToPath: false, duration: 6.0)
sprite.runAction(SKAction.repeatActionForever(followPath))
最佳答案
您必须绘制自己的路径,而不是使用 CGPathCreateWithEllipseInRect
,按照与您希望 Sprite 开始的位置相对应的顺序添加点。
尝试这篇文章中的方法:How to draw a circle starting at the top , 然后根据需要进行修改。
关于swift - 如何设置 CGPathCreateWithEllipseInRect 描述的路径的起点(或起始角度)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31350234/