Working with AudioStreamPlayer
In this recipe, we will use the AudioStreamPlayer node to play constant rain SFX or music, no matter where the player goes in the game. We will also use another AudioStreamPlayer node to create SFX of a gunshot to show off the new polyphonic support, which allows you to repeat the same sound multiple times on top of itself, using one AudioStreamPlayer node without any distorting sounds.
Getting ready
For this recipe, open Godot 4 and start a new project called Chapter 7
. In the Scene tab, click 2D to add a 2D scene. Click on Scene in the main menu next to Project, then select Save Scene As, and name the scene AudioStreamPlayer
.
How to do it…
Let’s download our gunshot SFX and music before we add the AudioStreamPlayer node to the scene:
- Go to https://pixabay.com/sound-effects/search/background and download the
Soft Rain Ambient
file. If you have your own MP3, WAV, or OGG files or find a different file on this website that...