【发布时间】:2015-10-23 10:30:06
【问题描述】:
我正在尝试基于点数组创建自定义 SKShapeNode。 这些点形成一个封闭的形状,最终需要填充形状。
这是我目前为止想出的,但由于某种原因,笔触画得很好,但形状保持空白。我错过了什么?
override func didMoveToView(view: SKView)
{
let center = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame))
let path = CGPathCreateMutable()
CGPathMoveToPoint(path, nil, center.x, center.y)
CGPathAddLineToPoint(path, nil, center.x + 50, center.y + 50)
CGPathMoveToPoint(path, nil, center.x + 50, center.y + 50)
CGPathAddLineToPoint(path, nil, center.x - 50, center.y + 50)
CGPathMoveToPoint(path, nil, center.x - 50, center.y + 50)
CGPathAddLineToPoint(path, nil, center.x - 50, center.y - 50)
CGPathMoveToPoint(path, nil, center.x - 50, center.y - 50)
CGPathAddLineToPoint(path, nil, center.x, center.y)
CGPathCloseSubpath(path)
let shape = SKShapeNode(path: path)
shape.strokeColor = SKColor.blueColor()
shape.fillColor = SKColor.redColor()
self.addChild(shape)
}
【问题讨论】:
标签: swift sprite-kit fill cgpath skshapenode