Reputation: 1
func gameOver() {
UserDefaults.standard.set(score, forKey: "recentScore")
if score > UserDefaults.standard.integer(forKey: "highscore") {
UserDefaults.standard.set(score, forKey: "highscore")
}
let menuScene = MenuScene(size: view!.bounds.size)
view!.presentScene(menuScene)
}
brain.exe
has stopped working why is the sound not playing? I have implemented the sound into the project but the program does not play any sound only shows the game over why is that so?
soundWIRDSPIELEN += 1
if soundWIRDSPIELEN == 1 {
run(SKAction.playSoundFileNamed("lose", waitForCompletion: true))
}
soundWIRDSPIELEN -= 1
if soundWIRDSPIELEN == 0 {
gameOver()
}
Upvotes: -3
Views: 50
Reputation: 564
Here is one thing I am sure you didn't though at.
You tell the compiler to run the lose sound
and exactly 0.001 seconds after, the compiler calls the gameOver
scene.
In other words, the compiler plays the sounds, but the user can't hear it because you exit the scene on gameOver.
You should tell the gameOver function to wait at least 0.5 seconds in order for the user to hear the sound. Also, use sound file extension.
run(SKAction.playSoundFileNamed("lose.mp3", waitForCompletion: false))
run(SKAction.sequence([SKAction.wait(forDuration: 1.0), SKAction.run(gameOver)]))
Upvotes: 1