【问题标题】:how to set starting point (or starting angle) of a path described by CGPathCreateWithEllipseInRect?如何设置由 CGPathCreateWithEllipseInRect 描述的路径的起点(或起点角度)?
【发布时间】:2015-07-10 21:03:42
【问题描述】:

我有一个遵循 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))

【问题讨论】:

    标签: swift ellipse skaction cgpath


    【解决方案1】:

    您必须绘制自己的路径,而不是使用CGPathCreateWithEllipseInRect,按照与您希望精灵开始的位置相对应的顺序添加点。

    试试这个帖子里的方法:How to draw a circle starting at the top,然后根据需要修改。

    【讨论】:

      【解决方案2】:

      @PatrickLynch ...谢谢我能够从圆形路径的最高点开始获取我的精灵,就像这样...
      var path = CGPathCreateMutable() CGPathAddArc(path!, nil, 100, 100, 100, CGFloat(M_PI_2) , CGFloat(2*M_PI + M_PI_2) , false) var followArc = SKAction.followPath(path, asOffset: true, orientToPath: false, duration: 2.0) sprite.runAction(followArc)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-02-18
        • 2013-06-09
        • 2021-12-27
        • 2017-06-22
        相关资源
        最近更新 更多