A short guide for anyone bringing original music into a GameMaker game and wondering why the loop never quite sounds like the track.
GameMaker makes looping look easy. Play a sound with the loop argument set to true and it repeats forever:
audio_play_sound(snd_music, 100, true);
For a lot of games that’s the end of it. But it repeats the whole file, from the first sample to the last, so there’s no room for an intro that plays once, and no good place for the reverb that rings out after the last bar.
GameMaker can do better than that, and plenty of tutorials still don’t mention it.
How GameMaker loops a section
Since version 2023.2, GameMaker can loop just part of a sound. You give it a loop start and a loop end, in seconds, and it plays the file from the top, then repeats the section between those two points:
audio_sound_loop_start(snd_music, 12.5);audio_sound_loop_end(snd_music, 44.5);audio_play_sound(snd_music, 100, true);
Everything before 12.5 seconds plays once, as an intro. Then the music repeats from 12.5 to 44.5 seconds, for as long as it’s set to loop. One file, three lines, and the jump happens on GameMaker’s audio thread, not in your game’s step event, so it doesn’t depend on the frame rate.
Two things to know before you rely on it. The loop points live in your code, not in the file: GameMaker doesn’t pick them up from markers in a WAV or OGG, so someone has to type the numbers in. And you need a current GameMaker. The 2026 LTS release has loop points, and so does every monthly release since 2023.2. The older 2022 LTS only loops whole files.
Why the tail is the hard part
Most music keeps sounding after the last bar of the loop: reverb, delay, a final note ringing out. That’s the tail, and a single looping sound gives you two bad choices.
Set the loop end where the music loops, and GameMaker jumps back the moment it gets there. The tail sits after the loop end, so it never plays. Every time the music wraps, the reverb stops dead and the next pass starts dry.
Loop the whole file with the ring-out left on the end, and GameMaker plays the tail as part of the loop. Now every pass runs long by the length of the tail, the restart lands late, and the rhythm of the loop falls apart.
There’s no setting that lets the tail ring over the restart, because one sound has one playhead. So the fix has to happen in the audio file itself.
Fold the tail into the start of the loop
Take the ring-out that sounds after the loop end, mix it into the opening of the loop, and cut the file so it ends exactly at the loop end. Now the audio at the loop start already carries the tail, and when GameMaker makes its jump, the reverb is simply there. This is called a folded tail.
It has one cost worth knowing: the very first time the loop plays, you also hear that folded-in tail at its start, before anything has actually rung out. An intro in front of the loop start covers it, which is one more reason the intro-plus-loop file is the good way to do this in GameMaker. With the file cut at the loop end, you can also leave the loop end at 0, which GameMaker reads as the end of the sound.
The details that bite
The numbers are in seconds, and a rounded number like 12.5 can land a sample or two away from where your loop really is. On some material that’s enough for a click. If you work the numbers out by hand, take the exact sample position, divide it by the sample rate, keep all the decimals, and listen to the seam in the game.
Set both points, not just the start. And loop points don’t work with GameMaker’s audio queues or sync groups, so music that’s built on either of those needs a different approach. Streamed music is fine.
For the format, use OGG. GameMaker takes WAV, MP3 and OGG, and its own manual suggests OGG or MP3 for music because the files are so much smaller.
Endings
GameMaker has a neat trick for endings that almost nobody uses. If your file carries on past the loop end with a composed ending, turn looping off while the music plays:
audio_sound_loop(ins_music, false);
The loop finishes its current pass and the music plays on into the ending, with no second file and no timing code. The catch is that it waits for the end of the pass, so with a long loop the ending can take a while to arrive.
If your file stops at the loop end, the clean way out is a fade:
audio_sound_gain(ins_music, 0, 2000);
Then stop the sound once the fade is done.
How Loopsmith makes this easier
This is the part I built Loopsmith to take off your plate. You finish the music, and it does the setup.
- If you’re the composer, you don’t need to know any of this. You hand over one OGG and a few lines of code, and the developer pastes them in.
- The tail is folded for you. The GameMaker preset renders the loop with its tail folded into the start and the intro in the same file, cut to exactly the loop length.
- The code is written for you. Copy the GameMaker lines from Loopsmith with the loop start and loop end already filled in, to the decimal, for the file you just exported.
- You hear it the way the game will play it, before it’s in GameMaker: the restart, and a check that flags a click, a loudness jump or a cut-off sound at the loop point.
The demo is the full app with three free tracks you can export as often as you like, which is enough to hear one of your own tracks looping in your own GameMaker project tonight. It’s Windows, and it costs nothing to find out.
If you also work in Ren’Py, it loops one file the same way, with the same folded-tail fix. The full map of which engine reads what is in How Game Engines Handle Loop Points in Audio Files.
Austin Haynes is a composer for games, including Cognition: An Erica Reed Thriller (AdventureGamers Best Music of 2013) and The Silver Lining. If your project needs music, you can hear his work at austinhaynesmusic.com.