diff --git a/getting_started/first_2d_game/07.finishing-up.rst b/getting_started/first_2d_game/07.finishing-up.rst index dd77a0d27cb..b37841d9bd8 100644 --- a/getting_started/first_2d_game/07.finishing-up.rst +++ b/getting_started/first_2d_game/07.finishing-up.rst @@ -35,13 +35,60 @@ audio file. All audio is automatically imported with the ``Loop`` setting disabled. If you want the music to loop seamlessly, click on the Stream file arrow, -select ``Make Unique``, then click on the Stream file and check the ``Loop`` box. +select ``Make Unique``, then click on the Stream file and check the ``Loop`` box. To play the music, add ``$Music.play()`` in the ``new_game()`` function and ``$Music.stop()`` in the ``game_over()`` function. Finally, add ``$DeathSound.play()`` in the ``game_over()`` function. +.. tabs:: + .. code-tab:: gdscript GDScript + + func game_over(): + ... + $Music.stop() + $DeathSound.play() + + func new_game(): + ... + $Music.play() + + .. code-tab:: csharp + + public void GameOver() + { + ... + GetNode("Music").Stop(); + GetNode("DeathSound").Play(); + } + + public void NewGame() + { + ... + GetNode("Music").Play(); + } + + .. code-tab:: cpp + + void Main::_ready() { + ... + _music = get_node("Music"); + _death_sound = get_node("DeathSound"); + } + + void Main::game_over() { + ... + _music->stop(); + _death_sound->play(); + } + + void Main::new_game() { + ... + _music->play(); + } + + Keyboard shortcut ~~~~~~~~~~~~~~~~~