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()
}
Here is one thing I am sure you didn't though at.
You tell the compiler to run the
lose soundand exactly 0.001 seconds after, the compiler calls thegameOverscene.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.