GameMaker: Studio comes with two different sound engines for controlling the various audio in games: GM:S Audio and Legacy Sound. These systems are completely independent from each other and you can have one system or the other active in a game.
The GM:S Audio engine is the new, more robust sound system that was designed to allow a full 3D soundscape through the use of emitters and listeners. Emitters allow for the positioning in game space where sounds are going to occur. There are functions for adding falloff of the sounds, velocity to emulate movement, and more. Listeners give even more control by dictating how the sound is played based on where the player is in the game, including their orientation and velocity. If you do not declare a listener, then the sounds become universal. This will eventually become the primary audio engine in GameMaker: Studio, but because of the HTML5 audio issues, it doesn't work properly in all browsers.
The Legacy Sound engine is the original sound system that GameMaker used and as the name indicates, this engine is no longer being actively developed and many of the functions have already been made obsolete. It is a much simpler system with no 3D capabilities, though for most games this will be more than enough. The one big benefit this engine has is that the audio should work in all browsers.
We will be using the Legacy Sound engine throughout this book to ensure maximum capability, but we need to know how to use the GM:S Audio engine for the future. Let's test these features by creating a very simple demonstration of positional sound. We are going to create an object in our room and make it play a sound that can only be heard as the mouse approaches the location.
snd_Effect
.Chapter 2/Sounds/Effect.wav
. Make sure the Kind is set to Normal Sound.obj_Sound
.scr_Sound_Create
. First, we need to create an emitter and capture it in a variable:sem = audio_emitter_create();
audio_emitter_position(sem, x, y, 0);
audio_emitter_falloff(sem, 96, 320, 1);
audio_play_sound_on(sem, snd_Effect, true, 1);
sem = audio_emitter_create(); audio_emitter_position(sem, x, y, 0); audio_emitter_falloff(sem, 96, 320, 1); audio_play_sound_on(sem, snd_Effect, true, 1);
scr_Sound_Step
.0
.audio_listener_position(mouse_x, mouse_y, 0);
obj_Sound
object, add a Step | Step event and drag an Execute Script icon into the Actions with the step script attached.obj_Sound
object into the center of the room.You should be able to hear the sound quietly and as you move the mouse around closer to the center of the screen the louder it should become. If you have surround sound or headphones, you will also notice that the sound moves from the left to the right channels. This is just a sample of what can be done with the GM:S Audio engine and it will be exciting to use once it works in all browsers.
18.223.213.238