Tutorial 6: In this tutorial we will explore different ways to add sounds to your game.
Adding sounds to the lazer / bullet
In the Asset Browser resources menu:
Create a sound Asset
Name it sndPlayerLazer
Click on the 3 dots in the window that appears
From your spaceshooter-assets, browse to sounds folder and choose the sndLaser wave file *Note: I have listed some websites where you can get sounds from at the end of this tutorial
Inside the sounds settings windows you can change the volume of the sound, to lower it sound in the game if you want.
In Target Options, change the Output to Stereo, if not already chosen.
Open the Player Object from the Resources menu. Double click into the Key Press Z event you already created.
Add the following code to the Key Press Z event, under the instance_create_layer() function, but inside the if statement:
//audio function takes 3 arguments
//reference to the soundfile, priority, loop(true / false)
audio_play_sound(sndPlayerLazer,1,false);
Play Music in the Game
To play music in your game, you must have a long enough music sound track that can loop on itself.
You can find copyright free music on lots of websites – one site I recommend is https://www.looperman.com/
Go to the Resource menu and create a new sound called sndGameMusic
Click the 3 dots and browse to the Asset Resources / Sounds folder
Select the sndMusic file
Name the sound to sndGameMusic
Change the Volume to your liking and change the output to Stereo
Next, double click into the Player object, objPlayer
Add the following code to the Create event of the layer object:
audio_play_sound(sndGameMusic,1,true);
Run the game and see if the music plays
Music for each level / room of your game
Create an objects that will represent the music you want for each level of your game.
Add a Create event to the music object and use code similar to the below
if(room!=EndRoom1){ //we want to pause music in the end room
audio_pause_all();
}else {
audio_play_sound(sndGameMusic,1,true);
}
Add the music object into your game room
You can change the above code with an else if( ) statement to play different music based on each room
Tutorial 7: Creating Enemy Sprite in Game Maker Studio 2 Go to the Resources area on the right of your screen: Right click on Sprites and click Create Sprite Make sure to name your sprites accurately for future reference Example: always prefix your sprites with the letters spr Name your first enemy sprite sprEnemy1 Importing…
Tutorial 8: Creating Enemy Lazer / Bullet Go to the Assets Browser resources area menu: Right click on Sprites and click Create Sprite or you can click on Resources menu at the top of GameMaker studio. Make sure you name your sprites correctly – always prefix your sprites with the letter spr Name the sprite…
Tutorial 9: Spawning Enemies First, what does spawning mean? Spawning refers to a method in game design where your enemies automatically get created You will want to make your enemies appear at random in a top-down or side-scrolling shooter game, so that they do not become predictable every time the game is played. Placing hundreds…
Tutorial 16: Create a room with a view and camera effect A room with a view and camera, is when you create a large room but as a user plays the game, they only see a portion of the room at a time. This is useful when creating rooms for platform type games. Take for…
Tutorial 13: Creating a Player Healthbar In this tutorial we will learn how to create a player health bar by setting up a variable for the player health. The number assigned to this variable are the number of frames on the GIF. This tutorial could be replicated for lives. Create a Health Bar Sprite Create…
Physics in Game Maker Studio 2 The following is an introduction demo of how physics can work in Game Maker Studio 2. It will give you an introduction of how you could implement it in your game. Step 1: Create Sprites for Physics Objects The sprites you need for this demo can be downloaded from…
3 Comments
Add audio_stop_all(); to object restart button in end room to stop looping game music.
You can also have different music for each room by adding code like this to the Room Start event on your player object if you run into a problem with objects that represent your music:
if room = Room1 { audio_play_sound(YourSoundFileName,1,true); }
if room = Room2 { audio_stop_sound(YourSoundFileName); audio_play_sound(YourSoundFileName2,1,true) }
Add
audio_stop_all();
to object restart button in end room to stop looping game music.
You can also have different music for each room by adding code like this to the Room Start event on your player object if you run into a problem with objects that represent your music:
if room = Room1 {
audio_play_sound(YourSoundFileName,1,true);
}
if room = Room2 {
audio_stop_sound(YourSoundFileName);
audio_play_sound(YourSoundFileName2,1,true)
}
You can randomize what audio files plays if you have different sounds for the lazer with this code:
audio_play_sound(choose(sndPlayerLazer1, sndPlayerLazer2, sndPlayerLazer3), 1, false);