我正在使用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")
}
}