【问题标题】:How can I have an SKSpriteNode follow the same path back and forth?如何让 SKSpriteNode 来回遵循相同的路径?
【发布时间】:2021-05-27 00:16:21
【问题描述】:

我的代码被划分为许多文件,所以我希望我可以轻松地描述这一点。 我有一个从 A 点到 B 点的 CGMutablePath() 我在 A 点放置一个 SKSpriteNode 并执行:

yourline0 = SKShapeNode()
pathToDraw0.move(to: cgPoints[0])
pathToDraw0.addQuadCurve(to: cgPoints[1], control: cgPoints[2])

yourline0.lineWidth = 0
yourline0.path = pathToDraw0
yourline0.strokeColor = .clear

iconPath0 = pathToDraw0

SKAction.follow(iconPath0, asOffset: false, orientToPath: false, duration: 1))

我执行了 SKACtion,正如我所料,我的 SKNode 从 A 点到 B 点。很好。

我不确定如何扭转它,我从 dox 假设调用相同的 SKAction 会使 SKNode 从 B 点转到 A。

【问题讨论】:

    标签: xcode sprite-kit skspritenode


    【解决方案1】:

    您可以使用一种称为 reversed() 的方法。

    下面我给你的动作命名为“youraction”

                let youraction = SKAction.follow(iconPath0, asOffset: false, orientToPath: false, duration: 1)
                let reverseaction = SKAction.reversed(youraction)
                yourspritenode.run(reverseaction)
                
    

    或者,您可以在动作名称后使用 reversed 来反向运行它:

                yourspritenode.run(youraction.reversed())
    

    【讨论】:

      猜你喜欢
      • 2019-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-12
      • 2012-07-10
      • 2016-03-18
      • 1970-01-01
      相关资源
      最近更新 更多