ios - 使用 Sprite 套件和 swift 绘制线条

标签 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

有什么想法吗?

最佳答案

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

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

来做到这一点

祝你好运!

关于ios - 使用 Sprite 套件和 swift 绘制线条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25329921/

相关文章:

ios - 为什么数组使用 '===' 运算符来比较元素?

ios - 如何在uiview中进行西装搭配和排名?

iphone - 核心数据迁移 : How to delete the Core Data stack?

ios - queryForTable viewDidAppear、viewWillAppear 等不适用于 subview

ios - 通过指针地址修改只读 NSData 是否安全?

C++ 翻译成 objective-C

iphone - Xcode 在打开 xib 文件时崩溃

iphone 开发 : how to auto facebook login if the facebook app already logged in

swift - RxSwift - 与 Singleton 不同类型的队列可观察值

ios - 不能在 UNNotificationContentExtension 上使用 AutoLayout 约束