Game Maker Studio 2.3 - How To Add Sound Effects And Music

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
greetings and welcome my name is aaron craig with let's learns together helping you achieve your dreams through learning so in game maker there are several ways to play sounds and i'm going to be going over the basic ones which are to play pause stop and change the volume of the sounds in your game and then i'm also going to show you a little more advanced technique of actually playing sounds at a location within your game itself so these are things that are awesome for sounds that you want to be at a specific location like i'm going to show you a waterfall or a fire or maybe someone fighting off in the distance you want the player to actually hear it in that direction and then as they move closer it gets louder game maker has an entire engine system built in for that what i'm going to be using is the basic project of importing and animating sprites as you can see here the only thing i've done is gone in and bring in the tile set i used from my tile set video and i added an animation here of this waterfall to do that you just click on add animation choose the number of frames you want and then choose the frames you want inside of there and set the fps inside the room i've created this little waterfall and if you run it you'll actually see that well it's animated and i think it looks pretty cool we're going to use this to play a waterfall sound first we're going to play it as a waterfall sound that is just everywhere all the time so if you were to play like a jump or sound effect or a hit you probably want it to play the basic way as just coming in through both speakers that work exactly as you would expect but then i'm going to show you how to make it so the sound actually comes from the waterfall so as you get closer it gets louder and as you get further away it gets quieter alright let's go ahead and dive right into that now the syntax and functions to actually play audio in game maker are pretty simple if we open up the manual and search for audio you'll see it has a complete list of everything right here so you can check if an audio exists get the name and the resource type from the asset browser but the main one we're going to be looking at is just audio play sound that's how you actually play a sound and then you can pause it you can pause all of them you can resume a specific sound or all of them and same thing for stopping and you can check to see if something is playing the rest of these are a little more advanced and i'm not going to cover them but from the name you'll probably be able to figure out exactly what they are and what they do for the most part such as setting the track position setting the sound length and the pitch you can change all of that stuff within game maker which is really cool but first let's go ahead and look at audio play sound audio play sound takes three arguments you have the index which is the resource in the asset browser you actually want to play the priority which lower priorities will be stopped in favor of higher priority sounds now i've never actually had this happen before but i haven't had tons of sound playing at the same time but if you need something to always be on there give it a higher priority and you can start from zero to 100 or zero to one the numbers are completely arbitrary just whatever is higher will get prioritized over what's lower and then whether something is looping or not so it's audio play sound with those three arguments and then it returns the index now this is something if you're making a larger game and you want to be able to control specific sounds you're going to need some kind of sound manager to store all the indexes the actual sounds that are playing so you can individually pause and stop them i'll show you how to do it for a single one but in a larger game you're going to want to have a full manager so that you know exactly how to access everything that's playing and maybe where it's at so let's go ahead and set this up so what we're going to need is a sound so i've actually got a waterfall sound right here i'm going to bring it in and it just pops right in i'm using an mp3 and game maker accepts several different kinds of sound files but if yours doesn't work you can search online for whatever extension you have to mp3 and you should be able to just upload that sound effect and then download it once again and then import it with no problem all right i'm going to reload because sometimes it does this and then i'm going to bring this down to 0.1 and press play it kind of sounds like static so i don't want it to be really really loud but it works for what i want to do here and i'm going to rename this to spr waterfall no not spr waterfall snd waterfalls my prefix that i use for sounds you can name it whatever you want then in obj warrior i'm going to go ahead and just play this sound effect so audio play sound sound waterfall a priority of one and i'm going to set it to loop is true then i'm just going to click run game and you should be able to now hear it inside of our game and no matter where you go it's going to sound constant because it's just playing that waterfall music just out there and you use this same function to play sound effects music any audio you want this is how you would use it and there you go so that's how you just play a sound now let's try out those other functions i'm going to add a couple key pressed i'm just going to add a for letters so i'm going to put in p so this is going to be for pausing so i'm going to say audio pause and i can pass in a sound now you can pause it based on the resource itself so i could pass in sound waterfall here and this will pause it if i run this i'll press p and then it will stop playing now this way works but you should note that this is going to pause all instances of sound waterfall so if you had multiple sound effects playing for whatever reason you had multiple tracks in your game music you had mini enemies walking around and each one had a footstep whatever the case is if you pause it like this it's going to pause all of them instead what we want to do is save what this returns so i'm going to say water sound equals and this is going to give us back the specific id then i can say pause water sound and we can test this out by playing a second water sound as well so i'll just copy this place it right there and then i'll run the game again now it's going to be a little loud so i'm going to turn the volume down for you guys and if i press p it paused one of them which you should be able to hear a little bit quieter now so that's pausing specific sounds versus pausing all sounds now i'm going to go ahead and delete that because i don't want to play two of them and i'm going to add another key event this time i'll just add a space and this will actually play slash resume the sound so i'm going to say audio resume sound and i'll pass in that water sound id same thing here if you resume based on the resource name over here it will resume all of them which again might be what you want might not be what you want so i'll pause it i'll resume it and it picks up exactly where it is which you can't really tell because it's all just kind of static waterfall noise but it does pick up exactly where it is so if you wanted to actually stop it you would say audio stop sound and then that will actually cut it off and then if you play it again it will start from the beginning and you won't be able to resume it because it's stopped and not paused so along with all of these they have functions that you can use to check if things are paused or all of that kind of stuff you can say audio is and you can check to see if a specific sound is paused such as maybe you paused the background music while going into a cut scene or going into a menu and then when they come out of it if it is paused you want to resume it if something is playing then you might want to pause it if it is actually playing so those are great ways to check to see what you're doing and then what you should be doing with your sound effects and again we have audio resume all pause all and stop all and that's the basics of playing sounds and music and whatever else audio you want inside of game maker now the cooler sound effects which i'm going to show you take a little bit more work but the result is in my opinion most definitely worth it because it lets you actually play sounds at a specific spot in the game which is really really cool so let's take a look at those functions and exactly how the more advanced audio works now there are a couple levels to how advanced you want to get and game maker has a really great audio engine built in we're only going to go up one level but i will mention the more advanced one as well what i'm going to be showing you is how to use audio play sound at which is the most basic version of using 3d sound in your game now when i say 3d sound i don't necessarily mean that it needs to be a 3d game even though this is going to have a z-axis if your game is 2d which it probably is if you're using game maker then just set the z position to 0 and everything game maker can do 3d and that's why they have a z position here so we're going to be using this function audio play sound at it's got a lot more arguments so i'm going to break those down as we go but essentially we're going to choose a spot in our game to play a sound from but to make all of that actually work we have to set up other things such as an audio listener a listener is where the sound is actually being absorbed at they have a really great graphic right here in the manual so you can use things called emitters and those are basically audio play sound at but objects you set in your room to play specific sounds and that's more advanced than what i'm going to get into now but this is the idea behind it you set a sound to play at a specific spot and if it's an emitter it can actually move like with an enemy or a sentry or whatever and the listener moves around the level and it hears the sounds from either sound play at or these emitters based on where it's at so what that means is we need to move the listener and we also have to set the orientation of it now this looks kind of confusing and i don't know why the head is upside down in this one but what's happening here is we need to set which way our player is actually facing the world this again is using kind of a 3d model but essentially we just want to set it so that left is left and right is right like we're looking directly at the screen instead of using the z-axis to move and look around in different orientations okay let's go ahead and use some of these functions to get this set up so i'm going to comment out this basic playing sound because we don't want to do that anymore instead i'm going to say audio play sound at and this like i said takes a lot more arguments so let's break this down the sound id remains exactly the same sound waterfall then we have x y and z now in my room the waterfall is at 182 and 200. so i'm going to put that for the x and y 182 200 and the z keep at zero unless you actually have a 3d game in which you'd have a z-axis and how quickly the sound is going to disappear the first one is how far the player can hear it so i'm going to put it at 25 so we can hear it for a good distance now 25 is not pixels it's some other kind of measurement so it's relative to a hundred so a hundred is the default value and zero would be zero you can't hear anything and we don't want to have it at zero we don't want to have it at 100 we want to have it be a fairly short distance because i want to be able to really show you how it works in here the max distance is actually just going to be 5 and the falloff will be a 1 and that's the default value that it has this is going to loop it's going to have a priority of one and so that will actually play the sound but there are a couple other things like i showed you that we have to do the first one is the audio listener orientation so for this we're going to set mostly the default values i just want it to be 0 1 0 and then 0 0 1. we're not using the z axis and all we're setting is that the look at y is one and the look up z is one so that way we're facing the 2d plane and the sounds that we're playing they make sense where they're actually coming from and they work as you would expect without this the sounds are going to be a little bit different than what you would think like your head might actually be upside down so make sure you set the orientation here otherwise things are going to be messed up the other thing we need to set is the audio falloff model now there are several different models you can have and i'm not going to go into well i'm not really going to go into them at all you can see here that they have some graphs and you can choose which one is going to work we are just going to use the basic one this one kind of works exactly as you would expect as you get closer it gets louder and as you get further away it gets softer at a equal rate so we're just going to use that because that will work for exactly what we want to do so i'll paste that in here it's a constant so it picks it up then in the step event we need to set where our listener is so we're going to say audio listener position and we're just going to put in our x y and zero for the z and the last thing we need to do is come into sound waterfall and make sure that the output is set to 3d otherwise it's not going to work properly and then let's run it and test it out our waterfall should now come from the right or the left let's get closer so it might be kind of hard to tell because the waterfall is still kind of loud and the reason for that is we actually messed up in the crate event let's go back to the warrior so you can see here that we set the orientation and the falloff model which works for the entire game so you only choose one of these but this sound didn't have that model we have to actually play the sound after we set the model so i put that down there now when i run it it'll be good to go so it'll be much quieter and you'll easily be able to tell so you can hear there's a waterfall in the game as i get closer it plays at the full volume as you get further away it stops and then it completely stops if you get far enough away and that is 3d audio inside of your game which i think is really really cool and not as difficult as you might have thought to implement now the drawback of audio play sound at is it's just one location you can't move it once you set it that's where emitters come into play which again i'm not covering now but if you'd be interested let me know and that's what i've got for you i hope this helps and i hope you see that playing sounds and music and anything else inside of your game isn't as hard as you thought if you have any questions or comments please let me know hit me up find me on twitter ask them on here i try to respond to everybody and don't forget i have a book on game making coming out really soon it's going to be awesome to take absolute beginners and make them game developers within 30 days check that out if you're interested in the link below a huge thank you to all of the awesome people who support me over on patreon their names are on the screen now and every dollar pledged helps me create more awesome content you can support me for as little as one dollar a month and get access to exclusive perks like my discord server your name in the credits early access to my youtube videos and courses and more check it out at patreon.com letslearnthistogether.com or find the link in the description below and become a patron today [Music] [Music] you
Info
Channel: Let's Learn This Together
Views: 2,667
Rating: undefined out of 5
Keywords: GameMaker Studio, Game Maker Studio 2, GameMaker Studio Tutorial, Game Maker Studio 2 Tutorial, GMS, GMS 2, GMS Tutorial, GMS 2 Tutorial, Let's Learn This Together, GameMaker 2, GameMaker Projects, game maker studio play audio, game maker studio play sound, game maker studio play music, how to add sound in game maker studio 2, how to add music in game maker studio 2, game maker studio 2 sound effects, game maker studio 2 music, Game Maker Studio 2.3, game maker audio tutorial
Id: IZXhw1-iKV8
Channel Id: undefined
Length: 17min 55sec (1075 seconds)
Published: Tue Feb 02 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.