使用Sprite工具包和swift绘制线条

时间:2014-08-15 16:04:08

标签: ios xcode swift drawing sprite-kit

我正在使用Sprite套件和Swift来测定手指画线。

代码:

override func touchesBegan(touches: NSSet!, withEvent event: UIEvent!) {
    touch = touches.anyObject() as UITouch!
    firstPoint = touch.locationInNode(self)
}

override func touchesMoved(touches: NSSet!, withEvent event: UIEvent!) {
    var touch = touches.anyObject() as UITouch!
    var positionInScene = touch.locationInNode(self)

    lineNode.removeFromParent()
    CGPathMoveToPoint(pathToDraw, nil, firstPoint.x, firstPoint.y)
    CGPathAddLineToPoint(pathToDraw, nil, positionInScene.x, positionInScene.y)
    lineNode.path = pathToDraw
    lineNode.lineWidth = 10.0
    lineNode.strokeColor = UIColor.redColor()

    self.addChild(lineNode)
    firstPoint = positionInScene
}

override func touchesEnded(touches: NSSet!, withEvent event: UIEvent!) {

}

但获得的线条是空的,只有边框有颜色(图像)。

enter image description here

有什么想法吗?

1 个答案:

答案 0 :(得分:2)

SKShapeNode有一个名为fillColor的属性,默认设置为clearColor。在您的代码中,您只需将strokeColor(大纲)设置为红色,但您也应该将其设置为fillColor

您可以使用lineNode.fillColor = UIColor.redColor()

执行此操作 祝你好运!