swift - 如何设置 CGPathCreateWithEllipseInRect 描述的路径的起点(或起始角度)?

标签 swift ellipse skaction cgpath

我有一个 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/

相关文章:

swift - 正确检测同时 SKAction 的完成情况

ios - PFFile 到 PFImageView

ios - 为什么没有在我的 UITabBarItem 上调用 didSelectItem?

objective-c - Sprite Kit的接触计数

python - 如何平均划分椭圆的周长?

python - 从椭圆生成数组

swift - 无法将类型 'NSMutableArray' 的值转换为预期的参数类型 '[SKAction]'

ios - 如何通过segue发送多个变量

ios - 如何使用 Storyboard为我的 View Controller 编写和调用指定的初始化程序来初始化私有(private)属性?

c# - WPF:创建半椭圆按钮