gpt4 book ai didi

ios - 如何在 GameplayKit 中显示 GKPath

转载 作者:行者123 更新时间:2023-11-29 01:15:17 49 4
gpt4 key购买 nike

是否有显示 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)
}


}

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

最佳答案

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

由于您使用的是 SpriteKit,因此使用与 GKPath 相同的点集创建 CGPath 并不太难,然后将其分配给 SKShapeNode放在你的场景中。

您可以在 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)

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

关于ios - 如何在 GameplayKit 中显示 GKPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35259748/

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