【发布时间】:2014-08-15 16:04:08
【问题描述】:
我正在使用带有 Swift 的 Sprite 工具包来分析手指画线。
代码:
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!) {
}
但是得到的线条是空的,只有边框有颜色(图片)。
有什么想法吗?
【问题讨论】:
-
lineNode是什么类型? -
var lineNode = SKShapeNode()
-
在使用
CAShapeLayer时,我还通过设置fillColor取得了成功。 -
您如何使用 CAShapeLayer?你能发布一些示例代码吗?
-
你试过在实际设备上运行它吗?我在模拟器中看到了 SpriteKit 和抚摸路径的一些奇怪错误。
标签: ios xcode swift drawing sprite-kit