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.
Working on the audio with Audacity
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:
Creating a scene
Let's start by creating a new 2D Scene
.
Adding audio to Godot
Grab the .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.
Set Loop Mode
to Foward
and Loop Begin
and Loop End
to the sample values found in Audacity. Then, click Reimport(*)
:
Adding Audio Stream to the scene
In the scene tab, right click Node2D
and add a new child node of
the typeAudioStreamPlayer2D
:
Select the newly created AudioStreamPlayer2D
under 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.
Testing
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 End
!
Thank you
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!
Top comments (0)