我正在使用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!) {
}
但获得的线条是空的,只有边框有颜色(图像)。
有什么想法吗?
答案 0 :(得分:2)
SKShapeNode
有一个名为fillColor
的属性,默认设置为clearColor
。在您的代码中,您只需将strokeColor
(大纲)设置为红色,但您也应该将其设置为fillColor
。
您可以使用lineNode.fillColor = UIColor.redColor()