【问题标题】:Draw lines with Sprite kit and swift用 Sprite kit 和 swift 画线
【发布时间】: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


【解决方案1】:

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

你可以用lineNode.fillColor = UIColor.redColor()做到这一点

祝你好运!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-06
    • 1970-01-01
    相关资源
    最近更新 更多