In this article, I'm going to show you one way to loop music in Godot!
But first, we need some software installed before we start.
- I'm using version 4.1.1 of the engine.
- To work with the audio, I'm using Audacity.
- Some audio to work on: I'm using the following: https://opengameart.org/content/woodcocky.
Open Audacity and import the audio file, you should see something like this:
In the bottom panel, click on the cog wheel and select
Start and End of the Selection:
And on the little drop down to the right, select samples (Godot works with samples):
We have the information we need! Now, in Audacity, go to File > Export > Export as WAV:
Let's start by creating a new
.wav file we just exported and add to the
res:// folder of your project:
Now, with your
.wav file selected, click in the
Import tab in the panel above your
res:// folder, let's change some of the properties.
Loop Mode to
Loop Begin and
Loop End to the sample values found in Audacity. Then, click
In the scene tab, right click
Node2D and add a new child node of
Select the newly created
Node2D and this will open an Inspector for this node. In the
Stream property of your audio player, drag and drop the
.wav file, make sure
Autoplay is enabled.
Save your scene and press
F6 to run the current scene (or press this button).
Now, your audio will play normally, but will loop between the samples you've set int the
Loop Begin and
Switching engines is always a challenge, but learning Godot for the past few days feels great, the engine is lightweight, and
GDScript is a delight to work with.
Hope you find this article helpful!
See you in the next one!