【问题标题】:Why doesn't the sound play?为什么不播放声音?
【发布时间】:2019-02-23 13:26:18
【问题描述】:
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()
}

【问题讨论】:

    标签: swift audio sprite-kit playing


    【解决方案1】:

    这是我确信你没有想到的一件事。

    您告诉编译器运行lose sound,恰好在0.001 秒后,编译器调用gameOver 场景。

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

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

    run(SKAction.playSoundFileNamed("lose.mp3", waitForCompletion: false))
    run(SKAction.sequence([SKAction.wait(forDuration: 1.0), SKAction.run(gameOver)]))
    

    【讨论】:

      猜你喜欢
      • 2022-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-13
      • 1970-01-01
      相关资源
      最近更新 更多