Swift SKAction中的代码运行操作未执行

Swift SKAction中的代码运行操作未执行,swift,sprite-kit,skspritenode,skaction,Swift,Sprite Kit,Skspritenode,Skaction,由于某种原因,SKAction.run操作中的代码块永远不会执行 要澄清的是,startAction中的两行由于某种原因从未运行过,即使其他行确实运行过 在这些行上设置断点证明这些行永远不会执行 有什么线索吗 // Set first frame let firstFrame = frames[0] let animationNode = SKSpriteNode(texture: firstFrame) animationNode.position = CGPo

由于某种原因,
SKAction.run
操作中的代码块永远不会执行

要澄清的是,
startAction
中的两行由于某种原因从未运行过,即使其他行确实运行过

在这些行上设置断点证明这些行永远不会执行

有什么线索吗

    // Set first frame
    let firstFrame = frames[0]
    let animationNode = SKSpriteNode(texture: firstFrame)
    animationNode.position = CGPoint(x: x, y: y)

    // Set start action
    let startAction = SKAction.run({
        gAudio.playSound(file: .TestSound) // Never runs
        self.animationLayer.addChild(animationNode) // Never runs
    })

    // Set rest of animation
    let timePerFrame = 0.5
    let animationAction = SKAction.animate(with: frames, timePerFrame: timePerFrame, resize: false, restore: true)
    let removeAction = SKAction.removeFromParent()
    let animationSequence = SKAction.sequence([startAction, animationAction, removeAction])

    // Run animation
    animationNode.run(animationSequence)

在将节点放置到场景中之前,不会为节点触发操作,您将面临鸡和蛋的两难选择。要在节点(蛋)存在于世界中(鸡生同一个蛋)之后将节点(蛋)添加到场景(鸡)。您需要使用其他工具将节点放置在场景中,然后节点将能够运行操作


将开始操作放在场景上,而不是节点上,它应该开始运行

run立即运行,但块将进入队列,并且不能保证在调用run的准确时间启动,因此一旦启动它,将启动下一个序列,因此,在运行中的任何内容都无法完成之前,从父节点中删除节点happen@Knight0fDragon非常感谢,为什么不把它贴出来作为答案呢?这似乎可以解释问题,不是吗?只有当动画没有运行时either@Knight0fDragon仅当动画未运行时?如果你对这些细节有把握的话,你能给出一个答案吗?动画动作再次感谢!实际上,您的解释中最有见地的部分是关于计时操作以及如何保证包含
run
操作的一系列操作。还想包括这一点吗?不,因为它与您的问题无关,只会混淆people@Knight0fDragon你能帮我看看这个帖子吗。我已经做了很长时间了