如何在SpriteKit中停止/删除序列?

时间:2016-09-16 00:57:46

标签: ios swift sprite-kit

我正在使用SpriteKit' playSoundFileNamed按顺序播放一系列声音片段。问题是当我退出PlayingState停止时。与SKAudioNode不同,我无法命名和枚举它们。因为声音片段是SKAction s,我可以运行它们并分配一个键并单独停止它们,但是当我将它们添加到下面的sequence时,声音在状态退出时不会停止。如何停止sequence

class PlayingState: GKState {


    unowned let scene: GameScene  

     var kQuoteNum = 6


    init(scene: SKScene) {
        self.scene = scene as! GameScene
        super.init()
    }

    override func didEnterWithPreviousState(previousState: GKState?) {


        //Build array of quotes from resources folder
        var quoteArray = [SKAction]()

        for i in 0..<kQuoteNum {
            quoteArray.append(SKAction.playSoundFileNamed("quote\(i).wav", waitForCompletion: true))

            }



        //Sound
        scene.runAction(SKAction.sequence(quoteArray), withKey: "playQuotes")


    }

    override func willExitWithNextState(nextState: GKState) {
        scene.removeActionForKey("playQuotes")
    }
}

0 个答案:

没有答案