从点阵快速绘制平滑曲线

时间:2015-01-03 17:48:36

标签: swift sprite-kit skshapenode

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

1 个答案:

答案 0 :(得分:1)

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

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)
相关问题