栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

迅捷的Sprite Kit游戏:圆圈以顺时针方向消失了吗?在计时器上?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

迅捷的Sprite Kit游戏:圆圈以顺时针方向消失了吗?在计时器上?

通过以固定间隔更改的path属性SKShapeNode,可以创建逐帧动画序列。要创建动画,设置该path属性为形状的顺序,与一个圆,两端开始什么也没有。您可以使用UIBezierPath(用于的包装器)CGPath通过以下步骤为动画创建形状:

  1. 将路径的“笔”移动到圆心
  2. 弧添加到与路径addArcWithCenter从startAngle到endAngle
  3. 在圆弧上与终点角相对应的点到中心的路径上添加一条线
  4. 更改endAngle固定金额
  5. 重复步骤1-4
    这是上述步骤的实现:

    override func didMove(to:SKView) {

    let circle = SKShapeNode(circleOfRadius: 50)circle.fillColor = SKColor.bluecircle.strokeColor = SKColor.clearcircle.zRotation = CGFloat.pi / 2addChild(circle)countdown(circle: circle, steps: 20, duration: 5) {    print("done")}

    }

    // Creates an animated countdown timer
    func countdown(circle:SKShapeNode, steps:Int, duration:TimeInterval, completion:@escaping ()->Void) {
    guard let path = circle.path else {
    return
    }
    let radius = path.boundingBox.width/2
    let timeInterval = duration/TimeInterval(steps)
    let incr = 1 / CGFloat(steps)
    var percent = CGFloat(1.0)

    let animate = SKAction.run {    percent -= incr    circle.path = self.circle(radius: radius, percent:percent)}let wait = SKAction.wait(forDuration:timeInterval)let action = SKAction.sequence([wait, animate])run(SKAction.repeat(action,count:steps-1)) {    self.run(SKAction.wait(forDuration:timeInterval)) {        circle.path = nil        completion()    }}

    }

    // Creates a CGPath in the shape of a pie with slices missing
    func circle(radius:CGFloat, percent:CGFloat) -> CGPath {
    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 bezierPath.cgPath
    }



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/417874.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号