SKAction 运行 动作中的代码未执行

Code inside SKAction run action not executing

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)

在将节点放置在场景中之前,不会为该节点触发操作,这里存在先有鸡还是先有蛋的困境。你想在节点(蛋)存在于世界(鸡生下同一个蛋)之后,将节点(蛋)添加到场景(鸡)中。您需要有其他东西将节点放在场景中,然后节点才能 运行 执行操作。

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