0

有没有显示 GKPath 的技巧?

例如我的路径:

class ScenarioPath: GKPath {

    //SET
    //   |  |  |  |  |  |
    // --A--B--C--D--E--F--
    //   |  |  |  |  |  |
    //6 punti con raggio quasi 600 e lato 500 va bene per scenario 2K * 3K
    static let lato = Float(500.0)
    static let maxY = Float(0.0)
    static let radius : Float = 600.0

    static let maxYNormalize = maxY - radius

    static let pts = [
        vector_float2(-lato,maxYNormalize),
        vector_float2(+lato,maxYNormalize),
        vector_float2(-2*lato,maxYNormalize),
        vector_float2(+2*lato,maxYNormalize),
        vector_float2(-3*lato,maxYNormalize),
        vector_float2(+3*lato,maxYNormalize)]


    init () {
        super.init(points: UnsafeMutablePointer(ScenarioPath.pts), count: ScenarioPath.pts.count, radius: ScenarioPath.radius, cyclical: true)
    }


}

我正在寻找一个简单的函数来显示这条路径。谢谢

4

1 回答 1

1

GameplayKit 不是图形框架。它是一个低级工具包,可用于任何图形框架。它没有任何用于绘制GKPaths 的功能,因为解释路径的方式至少与图形工具包和坐标系一样多。

CGPath由于您正在使用 SpriteKit,因此使用与您的相同的一组点来制作 a 并不难GKPath,然后将其分配给 aSKShapeNode以放置在您的场景中。

您可以在他们的两个较大的演示项目中找到执行此操作的 Apple 示例代码:AgentsCatalogDemoBots

这里有一些帮助您入门:

// BTW, vector_float2 just a typealias for float2,
// and is ArrayLiteralConvertible, so you can write your array shorter:
let pts: [float2] = [
    [-lato,maxYNormalize],
    [+lato,maxYNormalize],
    // ...
]

// CGPoint extension to make the conversion more readable and reusable
extension CGPoint {
    init(_ vector: float2) {
        self.init(x: CGFloat(vector.x), y: CGFloat(vector.y))
    }
}

// make array of CGPoints from array of float2
let cgPoints = pts.map(CGPoint.init)
// use that array to create a shape node
let node = SKShapeNode(points: UnsafeMutablePointer(cgPoints), count: cgPoints.count)

当然,这假设您的路径是在与场景相同的坐标系中指定的。如果没有,您将需要一些转换。

于 2016-02-08T01:27:26.783 回答