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
In a computer game a sprite is the name usually given to a two-dimensional bitmap computer graphic, designed to be integrated into a level, intro or exit screen. They can be static or animated. History of sprites Sprites were commonly used in 2D game design in the 1980s and 1990s, for designing player and enemy characters, before…
Over the coming weeks and months, we will explore how to build a simple 2D Top-Down Space Shooter computer game using the popular game development engine called GameMaker Studio. You will learn how to create sprites, learn to code to make your player move around a game environment, code spawning enemies, enemy collisions, making the…
To create enemy waves You need to have followed the tutorial on creating a persistent object in the previous tutorialCreate a score that keeps its value between rooms. Add this global variable to the Create event of objVarPersist: global.wave=1; Create an object called objEnemyWaves In Create event add the following code: //wait 10 seconds for…
Tutorial 11: Create an End Screen Based on the previous tutorial, on our players Step event, we said that when a players lives reach 0 we want the game to go to an end room. Create an End Room Duplicate your game room. Right click on the room in the Asset Browser and click duplicate….
Tutorial 5: Making your player shoot in GameMaker Studio 2 In this tutorial we will step through how you setup your player object to shoot lazers or bullets in GameMaker Studio 2 Create the player’s lazer / bullet sprite In the Assets Browser Resources menu (usually located on the right side of GameMaker studio 2)…
Tutorial 14: Creating a Light Effect in Game Maker Studio 2 You could demonstrate this effect in a separate room instead of your main playing room. If so, create a button to it on the start screen. Create a new object called objLight Add a Create event to this object with the following code: ///…
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);