-3
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已停止工作 为什么没有声音?我已经在项目中实现了声音,但程序没有播放任何声音,只显示游戏结束,为什么会这样?

soundWIRDSPIELEN += 1

if soundWIRDSPIELEN == 1 {
    run(SKAction.playSoundFileNamed("lose", waitForCompletion: true))
}

soundWIRDSPIELEN -= 1

if soundWIRDSPIELEN == 0 {
    gameOver()
}
4

1 回答 1

1

这是一件事,我敢肯定你没有。

您告诉编译器运行lose sound0.001 秒后,编译器调用gameOver场景。

换句话说,编译器播放声音,但用户听不到它,因为您在 gameOver 上退出了场景。

您应该告诉 gameOver 函数等待至少 0.5 秒,以便用户听到声音。另外,使用声音文件扩展名。

run(SKAction.playSoundFileNamed("lose.mp3", waitForCompletion: false))
run(SKAction.sequence([SKAction.wait(forDuration: 1.0), SKAction.run(gameOver)]))
于 2019-02-24T21:03:36.663 回答