gpt4 book ai didi

swift - 从点数组快速绘制平滑曲线

转载 作者:行者123 更新时间:2023-11-30 10:19:43 26 4
gpt4 key购买 nike

我正在 Xcode 中使用 swift 和 sprite-kit 开发一个应用程序,并且我有一个排列在椭圆形中的点数组。我想知道如何绘制一条连接阵列点的平滑白色曲线。我很确定它与 SKShapeNode 有关,但我不确定如何做到这一点。预先感谢您的帮助。

最佳答案

如果你想要一个完美的椭圆,你可以使用:

convenience init(ellipseInRect rect: CGRect)

convenience init(ellipseOfSize size: CGSize)

如果您只需要使用这些点,您可以创建一个 CGPath,并使用以下命令创建一个 SKShapeNode:

convenience init(path path: CGPath!)

convenience init(path path: CGPath!, centered centered: Bool)

可以在以下链接找到更多信息:

CGPath:https://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/CGPath/index.html

和 SKShapeNode:https://developer.apple.com/library/prerelease/ios/documentation/SpriteKit/Reference/SKShapeNode_Ref/index.html#//apple_ref/occ/clm/SKShapeNode/shapeNodeWithPath:centered :

最后,这是所有 4 个操作:

let rect = CGRect(x: 10, y: 10, width: 30, height: 40)
let size = rect.size
//for convenience init(ellipseInRect rect: CGRect)
let ellipse1 = SKShapeNode(ellipseInRect: rect)
//for convenience init(ellipseOfSize size: CGSize)
let ellipse2 = SKShapeNode(ellipseOfSize: size)

//path is a little harder to explain without more context
let path = CGPathCreateWithRect(rect, nil)
//for convenience init(path path: CGPath!)
let ellipse3 = SKShapeNode(path: path)
//for convenience init(path path: CGPath!, centered centered: Bool)
let ellipse4 = SKShapeNode(path: path, centered: true)

关于swift - 从点数组快速绘制平滑曲线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27757743/

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