A game can be visually impressive and still feel strangely empty without audio. Footsteps make movement feel physical, impact sounds make attacks more satisfying, and background music establishes the mood before the player reads a single line of dialogue.
GameMaker includes a built-in audio engine for importing, playing, controlling, and positioning sounds.
It supports common audio files such as WAV, MP3, and OGG, along with tools for looping music, changing volume and pitch, pausing playback, managing memory, and creating positional sound.
Learning how audio works in GameMaker is not only about calling one function. You also need to understand the difference between a sound asset and a playing sound instance, choose suitable file settings, prevent unwanted repetition, and keep music balanced with sound effects.
This guide explains the essential audio workflow in beginner-friendly terms, with practical GML examples you can adapt for platformers, RPGs, shooters, and other 2D games.
What Is a Sound Asset in GameMaker?
A sound asset is an audio file imported into your GameMaker project. It may contain a jump effect, explosion, menu click, voice line, ambient loop, or complete music track.
You create a new sound through the Asset Browser and load the file in the Sound Editor. GameMaker accepts WAV, MP3, and OGG files, and the editor lets you preview the audio, adjust its default volume, configure compression, and choose export settings.
Use clear asset names so they are easy to recognise in code:
snd_player_jump
snd_coin_collect
snd_enemy_hit
snd_level_music
The snd_ prefix is optional, but it helps distinguish audio from objects, sprites, rooms, and other resources.
A sound asset is not the same as the sound currently coming from the speakers. It is the stored resource from which GameMaker creates individual playback instances.
How to Play Sound Effects with GML
The simplest way to play audio is with audio_play_sound():
audio_play_sound(snd_coin_collect, 10, false);
The first argument is the sound asset. The second is its playback priority, and the third determines whether the sound loops. Setting the loop argument to false plays the sound once.
Priority becomes important when the number of simultaneous sounds exceeds the available audio-channel limit. GameMaker favours higher-priority sounds over lower-priority ones, although the exact number scale is up to you.
A player-death sound could therefore use a higher priority than a quiet footstep:
audio_play_sound(snd_footstep, 1, false);
audio_play_sound(snd_player_death, 100, false);
Play effects in response to meaningful events. A coin sound might belong in a Collision Event, while a sword effect could play when an attack begins.
Avoid calling a one-shot sound unconditionally in the Step Event. Because that event runs continuously, the game may try to start a new copy every step.
Sound Assets vs Sound Instances
Every call to audio_play_sound() creates a new sound instance, also known as a voice. The function returns a unique ID that lets you control that specific playback.
Store the returned value when you need to pause, fade, modify, or stop one copy:
music_instance = audio_play_sound(
snd_level_music,
100,
true
);
You can then stop only that instance:
audio_stop_sound(music_instance);
Passing a sound-instance ID affects that individual playback. Passing the original sound asset to functions such as audio_stop_sound() may affect every active instance created from that asset.
This distinction matters when several enemies use the same sound. You may want to reduce the volume of one nearby enemy without changing every instance of snd_enemy_move.
How to Play and Control Background Music
Background music usually needs to loop until the player enters another room, reaches a new area, or returns to a menu.
A basic music controller can use:
if (!audio_is_playing(snd_level_music))
{
music_instance = audio_play_sound(
snd_level_music,
100,
true
);
}
The audio_is_playing() function can check a sound asset or a specific sound instance. When given an asset, it returns true if any instance of that sound is playing. Paused audio is also considered active by this function.
Music can be paused and resumed without restarting the track:
audio_pause_sound(music_instance);
audio_resume_sound(music_instance);
This is useful for pause menus. If the player leaves the level permanently, use audio_stop_sound() instead. Pausing preserves the playback position, while stopping ends that instance.
Place persistent music management in a controller object rather than starting the track from several unrelated objects. Otherwise, multiple copies may begin playing over one another.
Adjust Volume, Fades, and Pitch
GameMaker refers to audio volume as gain. A gain of 0 is silent, while 1 is normally treated as full volume.
You can change one playing sound instance with:
audio_sound_gain(music_instance, 0.5, 1000);
This fades the music toward half volume over 1,000 milliseconds. Setting the time to zero changes the gain immediately. Values above one may cause clipping or distortion depending on the sound and target platform.
To fade music in:
music_instance = audio_play_sound(
snd_level_music,
100,
true
);
audio_sound_gain(music_instance, 0, 0);
audio_sound_gain(music_instance, 1, 2000);
Pitch can also be changed for a sound asset or individual playback instance. Slight pitch variation is useful when one effect repeats frequently, such as footsteps, impacts, or coin pickups.
audio_play_sound(
snd_footstep,
1,
false,
1,
0,
random_range(0.95, 1.05)
);
The optional arguments set gain, starting offset, and pitch for that new instance. Keep variations subtle so they sound natural rather than broken.
Choose the Right Audio Format and Settings
WAV files are commonly suitable for short effects because uncompressed audio can begin quickly without requiring runtime decoding. MP3 and OGG files are usually smaller and are often more practical for music or longer sounds.
The Sound Editor offers uncompressed, compressed, uncompressed-on-load, and streamed options. Compression reduces file size but adds some decoding work, while loading uncompressed audio into memory improves playback speed at the cost of additional memory use.
Streaming is especially useful for long music tracks because the audio can be read progressively instead of loading the complete decoded file into memory. It is generally unnecessary for very short effects.
Higher sample rates and quality settings usually increase file size. Listen on the devices you plan to support and choose settings that preserve acceptable quality without making the game package unnecessarily large.
Manage Audio with Audio Groups
Audio groups organise related sound assets and give you greater control over memory, volume, and platform exports. You might create separate groups for interface sounds, gameplay effects, dialogue, and music.
Sounds in audiogroup_default are normally loaded at startup unless they are streamed. Assets assigned to a custom group are not loaded until you call audio_group_load().
audio_group_load(audiogroup_level_one);
Audio-group loading is asynchronous, meaning the game continues running while the files load. Check whether the group is ready before depending on its sounds:
if (audio_group_is_loaded(audiogroup_level_one))
{
room_goto(rm_level_one);
}
When a group is no longer required, it can be unloaded to free memory:
audio_group_unload(audiogroup_level_one);
Audio groups become especially useful in games with many levels, characters, or voice lines. A small project with only a few effects may work perfectly well with the default group.
Create Positional Audio
Normal audio_play_sound() playback occurs at the audio listener’s position, so it is heard equally through the left and right channels by default. Positional audio places a sound elsewhere in the audio space, allowing distance and direction to affect what the player hears.
For a simple explosion, you can use:
audio_play_sound_at(
snd_explosion,
x,
y,
0,
100,
300,
1,
false,
10
);
The sound is played at the instance’s position with settings that control how its volume falls off over distance. A falloff model should also be selected when you want distance to affect gain.
Audio emitters provide more control for moving sources such as vehicles, rivers, machines, or enemies. An emitter’s position can be updated while its sound is playing:
audio_emitter_position(emitter, x, y, 0);
Emitters should be freed when they are no longer needed, usually in a Clean Up Event, to avoid leaving unused resources in memory.
Balance and Test Your Game Audio
Good audio is not simply loud audio. Music, interface effects, attacks, ambience, and dialogue should have clearly defined roles.
Important gameplay sounds must remain noticeable without making every action equally loud. A player-damage effect should normally attract more attention than a decorative environmental sound.
Use the Sound Editor and Sound Mixer to preview several assets and compare their levels. GameMaker’s Sound Mixer can play multiple sounds from one workspace and adjust their volume balance.
Also test with headphones, speakers, and lower system volume. Positional effects that sound clear through headphones may become difficult to notice through small laptop or mobile speakers.
Provide separate music and sound-effect controls when possible. Master volume can be changed with audio_set_master_gain(), which uses a linear scale from zero to one for a selected listener.
Audio in GameMaker begins with imported sound assets, but the real control comes from GML. Functions such as audio_play_sound() create sound instances that can be looped, paused, stopped, faded, or adjusted independently.
The Sound Editor helps manage file format, compression, volume, and export quality, while audio groups provide better memory control for larger projects.
Positional audio and emitters can make the world feel more alive by connecting sounds to locations and moving objects. Start with three simple elements: one interface click, one gameplay effect, and one looping music track.
Balance them carefully, prevent accidental repetition, and store playback IDs whenever you need precise control. Once that foundation works, experiment with fades, pitch variation, ambience, and directional audio.
