【问题标题】:What happens if I execute an SKAction run sequence on a node that is already executing another sequence?如果我在已经执行另一个序列的节点上执行 SKAction 运行序列会发生什么?
【发布时间】:2021-10-21 13:51:26
【问题描述】:

我有一个 SKSpriteNode 并在其上运行 SKAction:

theGem!.run(premAction, completion: {theGem!.run(repeatAction)})

似乎无法找到运行其他操作的正确步骤,例如:

theGem.run(endsequence, completion: {theGem.removeAllActions(); theGem.run(stopAction)})

我应该先停止上一个动作吗?
有没有办法关闭重复部分,以便第一个 SKAction 顺利结束?

【问题讨论】:

    标签: sprite-kit skspritenode


    【解决方案1】:

    通常 SKAction 会在同时运行 2 个或更多时合并。

    要运行一系列 SKAction,您通常会使用类似这样的方法,首先运行 premAction,然后运行 ​​repeatAction

    let sequence1 = SKAction.sequence([premAction, repeatAction])
    

    要运行序列,请使用:

    theGem.run(sequence1)
    

    如果计划是在某个时候运行另一个 SKAction 序列,您可以使用:

    theGem.removeAllActions()
    theGem.run(sequence2)
    

    或者,如果您更喜欢更严密监控的操作管理,则在您运行操作时为其分配一个键,如下所示:

    theGem.run(sequence1, withKey "seq1key")
    

    然后,当您想停止该特定操作时,请使用:

    theGem.removeAction(forKey: "seq1key")
    

    【讨论】:

    • 所以我应该删除一个正在重复的运行序列,“在”运行一个新序列之前? p.s.感谢您的关键提示。
    • 如果不再需要运行序列,那么是的,将其删除。在 sprite 上运行新的 SKAction 不会停止当前在其上运行的其他动作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-12-24
    • 2014-10-06
    • 2020-04-26
    • 1970-01-01
    • 2016-11-03
    • 2021-01-09
    • 2018-06-02
    相关资源
    最近更新 更多