ios - Swift 和 SpriteKit : how to implement non-fuzzy circle timer with SKShapeNode

标签 ios swift sprite-kit

下面的代码使用 SKShapeNode 实现了一个圆形计时器,其中一个圆片随着时间的流逝而消失。

不幸的是,由于 SKShapeNode 的限制,计时器是模糊的。

Answers like this没有解决这个问题,而且也很旧,可能不再适用。

1)有没有办法在没有这种模糊线的情况下使用 SKShapeNode?

2) 如果没有办法修复 SKShapdeNode,有什么替代方案可以实现类似的循环计时器?

    let timer = SKShapeNode(circleOfRadius: CGFloat(50))
    timer.fillColor = UIColor.red
    timer.strokeColor = UIColor.clear
    timer.lineWidth = 0
    timer.zRotation = CGFloat.pi / 2

    timer.path = self.circle(radius: CGFloat(50), percent: CGFloat(90))

fileprivate func circle(radius: CGFloat, percent: CGFloat) -> CGPath {
    // Adjust <percent> if less than 0
    let percent = percent < 0 ? 0 : percent

    // Generate circle path
    let start = CGFloat(0)
    let end = CGFloat.pi * 2 * percent
    let center = CGPoint.zero
    let bezierPath = UIBezierPath()
    bezierPath.move(to: center)
    bezierPath.addArc(withCenter:center, radius: radius, startAngle: start, endAngle: end, clockwise: true)
    bezierPath.addLine(to: center)

    // Return path
    return bezierPath.cgPath
}

最佳答案

着色器可能会完成您想要的,查看 http://battleofbrothers.com/sirryan/understanding-shaders-in-spritekit/

此外,根据 AppleDocs,SKShapeNode 不应在调试之外使用,过去使用它们时遇到过一些问题。

关于ios - Swift 和 SpriteKit : how to implement non-fuzzy circle timer with SKShapeNode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51317484/

相关文章:

ios - UNNotificationAction 按钮未显示,为什么?

ios - SpriteKit 添加 child 不工作

ios - 从 SKSpriteNode 引用当前 SKScene

ios - 找不到纹理图集

ios - 为什么 isUniquelyReferencedNonObjC 在这种情况下返回 false?

ios - xcode 6.01+ swift : What is the minimal project structure I must have/How to remove unneeded file references?

iphone - SQLite 数据库与多语言 iOS 6 应用程序

iphone - Objective-C 中小部件 API 的最佳实践

ios - SpriteKitNode 不动

ios - Swift - 如何识别哪个自定义 tableview 单元格已被修改?