我正在使用 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!) {
}
但是获取到的线条都是空的,只有边框有颜色(图像)。
有什么想法吗?
最佳答案
SKShapeNode
有一个名为 fillColor
的属性,默认设置为 clearColor
。在您的代码中,您只需将 linesColor
(轮廓)设置为红色,但也应该将 fillColor
设置为红色。
您可以使用lineNode.fillColor = UIColor.redColor()
祝你好运!
关于ios - 使用 Sprite 套件和 swift 绘制线条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25329921/