Selaa lähdekoodia

Add code examples for sound playing in the "first 2d game" tutorial

The last step in "Your first 2D game" (Finishing up) lacks code or
directions in general for C#. Add a short snipet that can be used
for reference and for copy and paste.

Fixes #8003
Jaime Crespo 1 vuosi sitten
vanhempi
commit
3f45d36502
1 muutettua tiedostoa jossa 48 lisäystä ja 1 poistoa
  1. 48 1
      getting_started/first_2d_game/07.finishing-up.rst

+ 48 - 1
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.
 All audio is automatically imported with the ``Loop`` setting disabled.
 If you want the music to loop seamlessly, click on the Stream file arrow,
 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()``
 To play the music, add ``$Music.play()`` in the ``new_game()``
 function and ``$Music.stop()`` in the ``game_over()`` function.
 function and ``$Music.stop()`` in the ``game_over()`` function.
 
 
 Finally, add ``$DeathSound.play()`` 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<AudioStreamPlayer>("Music").Stop();
+        GetNode<AudioStreamPlayer>("DeathSound").Play();
+    }
+
+    public void NewGame()
+    {
+        ...
+        GetNode<AudioStreamPlayer>("Music").Play();
+    }
+
+ .. code-tab:: cpp
+
+    void Main::_ready() {
+        ...
+        _music = get_node<godot::AudioStreamPlayer>("Music");
+        _death_sound = get_node<godot::AudioStreamPlayer>("DeathSound");
+    }
+
+    void Main::game_over() {
+        ...
+        _music->stop();
+        _death_sound->play();
+    }
+
+    void Main::new_game() {
+        ...
+        _music->play();
+    }
+
+
 Keyboard shortcut
 Keyboard shortcut
 ~~~~~~~~~~~~~~~~~
 ~~~~~~~~~~~~~~~~~