下面的代码使用 SKShapeNode 实现了一个圆形计时器,其中一个圆片随着时间的流逝而消失。
不幸的是,由于 SKShapeNode 的限制,计时器是模糊的。
Answers like this没有解决这个问题,而且也很旧,可能不再适用。
1)有没有办法在没有这种模糊线的情况下使用 SKShapeNode?p>
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/