【问题标题】:In Swift 4.2 - How can I animate a circle in SpriteKit在 Swift 4.2 中-如何在 SpriteKit 中为圆圈设置动画
【发布时间】:2018-10-27 12:55:58
【问题描述】:

我可以在两个物体的碰撞点画一个圆,但我想为它创建一个漂亮的动画(顺时针)。我了解如何在单视图应用程序中执行此操作,但我不能在 SpriteKit 中使用相同的实现。如何在 SpriteKit 中做到这一点?

这是我添加圆圈的代码 -

func drawCircleOnCollisionPoint(arrowName:String) {
    let circle:SKShapeNode = SKShapeNode(circleOfRadius: 15)
    circle.position = (arrowsCollidedWithTarget[arrowName]?.contactPoint)!
    circle.strokeColor = SKColor.red
    circle.glowWidth = 1.0
    circle.fillColor = SKColor.clear
    circle.zPosition = 50
    self.addChild(circle)
    DispatchQueue.main.asyncAfter(deadline: .now() + timeBetweenGames) {
        circle.removeFromParent()
    }
}

【问题讨论】:

  • 您想如何制作动画? Α?规模?尝试摆弄SKActionSKSpriteNode.run(_:) 方法。
  • 如果有意义的话,我想要一个闭环动画..?从屏幕上什么都没有开始,然后画一个圆圈(我希望你明白我的意思 - 如果需要,我可以添加一个 gif)

标签: swift animation sprite-kit


【解决方案1】:

试试这个:

让 action = SKAction.rotate(byAngle: -360, duration: 30)

circle.run(SKAction.repeatForever(action))

【讨论】:

  • 我看不出有任何区别。我在添加圆圈之前正在运行该操作。添加孩子后,我还尝试运行该操作...
猜你喜欢
  • 1970-01-01
  • 2021-11-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多