Gamemaker DND Platformer Tutorial - #19 Sound Design

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] if you're interested in making a detailed platformer just like this one within game maker using drag and drop then keep watching g'day gamers and welcome back to our drag and drop platformer series our series is drawing to a close soon so i wanted to add a much needed feature to our game that of sound the use of music and sound in your game can really elevate the player's experience and it's an area that should not be overlooked as it really does make a game feel complete when done correctly i'm going to show you how to approach the sound design process add appropriate sounds use situational sounds like player footsteps and also enable different music for different rooms before we start though you will notice i'm now using version 2.3 of game maker which i assume you are using as well there have been many changes with this version but one worth mentioning first is the new asset browser by default it'll sort all your resources alphabetically but you can go over here and choose custom order if you'd prefer to have them in any order you like there are also many other changes but we'll touch on some of those later so how do you approach adding sound well i like to first play the game and everywhere you think there should be a sound write down the sound you need once you have a list start compiling the sounds now a great place is down here under notes you can go down to create and create a note now i'm going to paste in the lists that i've compiled from our current game so this is the sound we need and now this is the sound file that we're going to use though i've already gathered the sounds for the game but where do you get them from well there is a great free website that i use to generate my sounds it's called bfxr.net this is what it looks like basically you click on the effect you want when you're happy with the sound you export it to a wave and then you can bring that into game maker you can also click the mutation button and it'll make a sound that is similar to the previous sound it's really good for getting the right sound that you're after now this site generates 8-bit chip sounds but you can even go up to the mixer and combine the sounds just to get what you need you should save each file and give it a name like snd underscore sound and then you update the list with that information so you know which sound belongs to which effect just like i've done here once you have all the sounds you can start to add them and see how they feel in the game sometimes i like to turn the sounds down as well if they're ones that play many times over so they don't get annoying for the player so here those sounds are i'm going to select them and then drag them over into the sounds group that will bring them all into game maker if this window comes up you can click save just to make sure they are saved now if you go over here right click and close all about this then you can easily close them all so let's look at the list we have and let's start adding the sounds but the first one is related to the picking up of the coins so let's go into the coin object let's go to the collision with the player because that's where we want to play the pickup coin sound so just here is where we pick up the coins if you type in audio you'll be taken to the audio code blocks and the first one just lets you play an audio sound so let's drag that in and let's select the sound which is the coin pickup now if you're playing a sound over and over it can get very repetitious so what you want to do is go down to set audio pitch drag that in and you can change the pitch of the current sound that's played but in order to do that we need to assign the sound to a variable i'm just going to call it snd and make it a temporary variable and now when i refer to the snd variable i'm actually referring to the sound that's playing so down here we can set the pitch and the sound we don't want to select something we want to use that reference variable and for the pitch one is the default sound so let's change that to a random range value between 0.8 and 1.2 and that'll just vary the pitch for each coin that we pick up now i'd also like to add a sound when the coin drops or bounces so let's go into the step event i'm going to right click and go to open parent event and our coin is a child of the o object parent and we did this so that we could have other objects that inherit the properties of what the coin does which means that it bounces when it spawns so that's why you could add other things to your game now when we bounce that happens in the collision event and bounces decrease by one so if bounce is decreased by one after the collision event runs that means we bounce and that means we want to play a sound effect so let's capture into a temporary variable what bounce was before we went into the collision script so let's just call this pre underscore bounce and we want to set it to whatever bounce is and when this runs let's have a look and compare if that's still the same so if pre-bounce is now not equal to bounce well that means we bounced in the collision event so we can run our sound so let's just play the sound of the coin bouncing and we're going to do the same thing where we want to vary the sound so let's drag in the pitch assign it to snd as a temporary variable and then we'll set snd to our random range once again a random range of 0.8 say to 1.2 now you can adjust these values if you're not happy with them but it gives you an idea so let's just test that out press play so we've got the coins we pick up they sound great and if we make the coins come out of the enemy we get a lot of sounds happening at once let's just check this one as well so when many coins fall the sound can be too busy and distracting so instead what we can do is check if the sound's already playing and if it is we don't play it again this way we can limit the number of sounds of the same type that are played so just under audio we can actually look for and if audio is playing code block let's drag that in and let's ask if this sound is already playing and if it's not playing well then we can play it and that will just limit how often we have to hear that sound now let's go to our list and see what's next we have the jumping of the player and the landing so the player jumping happens in our check jump script let's go into our scripts and let's go to our check jump and just here is where the player jumps so let's play a sound right there we want to have the player jump sound there it is there and then we need the sound for when we land well that actually happens in our air state so if we go to our player and then we go to our air state and then down here after we've landed on the ground we create some dust and that's when we know that we've hit the ground so right here we can play our sound and we just want to play the sound of landing great now look at our notes again and the next thing we had to do was the player footsteps now footsteps are something that add a really nice atmosphere to the game but they have to be done right so that when the player is stepping on the ground is when we're hearing the sound so let's go have a look at the player sprite and in the walk sprite so what we can see here is when we are walking it's not till there that the player actually touches the ground on frame four and then if we keep going we'll see the next one happens at frame nine so when our image index is either four or nine is when we're touching the ground and when we want to play the sound now remember though image index is a decimal it's incremented each step by the speed of the sprite so it's basically 8 over our room speed which is 8 over 60 so image index is incremented by 8 over 60 per step so we can't just check for when image index is 4 or 9 as it may never be exactly those values instead we can check the floor of image index which means round the value down so when you floor a number say 4.3 that's floored down to 4. when you floor 4.9 it's also floored down to 4. now that also means that the floor of image index will be 4 for multiple frames in a row so we should check that the sound is not being played before playing it and as long as the sound is long enough that will ensure it only plays once per footstep so let's go to the walk state just in here under the player's step event we have our walk state and let's create a check for a footstep i'm just going to do it under our check jump so i'm going to copy that and paste it and then i'll create another script and then we can just check for footstep now i'm going to take a copy of that name and go over to our scripts we're going to right click go to create and we want to create a new script i'm just going to give it the name of check footstep and let's just drag this up here so we can see it better now here's a new part of game maker 2.3 and that is the declare a new function code block so all scripts in 2.3 now are actually going to be declared as functions and all that means is that when you create the script you just need to apply it to the right here of the function code block so over here where you get to see the list everything is going to be indented except for the declare a new function and this also means you can actually have multiple functions in each script we're not doing that at the moment but it is something to be aware of so we want to check for our footsteps so we need to check if our floor of image index is equal to 4 or our floor of image index is equal to 9 and because we want to check two conditions we need to do that with an if expression so we're going to look for the floor of image index is equal to four or the floor of image index is equal to nine and if that's the case then we also first need to check if the audio is not already playing and that's of our footstep and if it's not playing well then we can play it now i want to vary the pitch of this again so i'm going to store the id into a variable and it's just a temporary variable and then we're going to go over and we're going to change the pitch of snd to be random range between say 0.7 and 1.3 i'm doing a larger range because the footstep sound that i have is really deep and changing the pitch actually doesn't make a huge difference but if you have a footstep sound that's not as deep as what i'm using you will notice a change in the pitch like this so let's press play and test that out [Music] so we can see there as we walk [Music] we're getting a sound each time that our foot touches the ground and we've got a jump sound and also a landing sound so they're all working well now let's go have a look at our list again and our next sound is for the collisions with the player and the enemy let's go into our player where we land on the enemy so that's going to be here in our collision with the enemy and this is the point here where we're landing on the enemy's head so let's drag across another play audio and let's select the sound for when we land on enemy now if we don't land on the enemy and we touch the enemy we actually get hurt or damaged and that happens down the bottom here so in this section here we can play the sound for if the enemy damages us so let's go here where the player gets damaged uh just here great now there's not many left we're looking at the sound for when the enemy dies or falls down now if we go and look at the enemy when they're dead that actually fall down not just here not yet not yet but right there at frame eight but then i flopped down and hit the ground until there and that's where i'd like to play the sound but that'll also give me the opportunity to show you an additional way to play sounds at particular frames so let's go to our enemy object and let's go to our step event and into our die state so just here just close some of these up now here's our die state so because our image index is possibly a decimal we need to check if it's greater than or equal to eight so when the enemy dies we only want to play the sound once so we need to do a check in here and i'm going to do an expression check again and we need to ask a question and say if our image index is greater than or equal to 8 because it's a decimal remember and i'm going to set a variable to tell us if the sound is already played i'm going to call it full sound played now the exclamation mark at the start indicates a not symbol which means that we want the opposite of whatever the value is so take a copy of that so let's go and create this variable just under variable definitions i'm just going to click add and create a full sound played and set it to false so that means the sound has not played yet we'll set it to true when the sound actually plays so if it hasn't played yet and were greater than image index then we can play the sound and it's the sound of the enemy dying but we also need to set this variable because we've played it once already so our fall sound played becomes true and that way we can limit the sound to only play once now the last sound that we had to do was the player dying and where that happens is in the check hp script because that's the point we move them into the die state let's go into our check hp script and we'll just drag this up here so we can see it and right here we move the player to the dead state now this is a great place to add the sound and the reason is because this code only runs once you can set up variables like i've just shown but really you want to look for opportunities where you only have to run the code once it's just more efficient than creating variables and managing it that way so right here we can just add the sound of the player dying and let's test it all out so we've got the sound of the coins we've got the sound of the damaging of the enemies and damaging of the player and the sound of when the player dies as well that's all great but you know what we really need and that is some music music really helps give your game some much needed atmosphere there are a few places where you can get free video game music to use in your games one such place is from oz.net this is his site i'll put a link in the description so you can get there but he's music is available under the creative commons license and that means you can use it in your projects as long as you give credit to the source and provide a link to the license i've downloaded two songs to use which are available in the description as well i'd like to add these songs and set it up so we have a different song playing when moving to different rooms to do so we will assign the music to a ds map which is a game maker data structure which basically can hold a key and a value the key is just a label describing what you are storing and the value is just what you want to store each ds map can hold any number of these keys so they are great for storing multiple pieces of data which you can retrieve later i like to think of a ds map as a chest which you can place envelopes in each envelope has a description written on it with some info inside you can then pull out any envelope you need and get the info from inside it so let's add a ds map to our game under the ogame create event so just down here if we type in map we can create a ds map now i'm just going to call ours music underscore map and just like we did with that ds list if you create a ds map you need to ensure you go to a clean up event and have it destroyed afterwards there is no drag and drop code for this so we want to put ds map destroy and we type the name of the map which is music map now let's bring the songs in that we need so just down here i've got two songs for each room i'm just going to drag them into the sounds folder here it is here and you want to click save if that occurs i'm just going to take a copy of the name and also i'm going to decrease these down to 0.4 from the volume because they are a little bit loud so let's close those and now that we have the names of the songs i want to add them to the ds map so here we can set a map value we want to know the name of the map so it's music underscore map now the key is our description on our envelope so for us it'll be the room we want the song to play in and then the value will just be the name of the sound resource so if we go look at our rooms so for our key we're just going to write the name of the room so r underscore level one and which song we want to play in that particular room i'm just going to paste in what i chose from before so it's room one music and it's called perihelium let's take a copy and a paste of that and we can do level two and we can take a copy of the other room name and press f2 and then control c and then we'll paste this one in like that so there are two map entries so as long as you put the name of the room and then the song that you want to play this system will work now when do we want to play the sound well the best time is when the room starts and we have a roon start event in ogame so let's use that now the first thing we want to do when we want to play the music is to know what we should be playing so we go over here to our map resources and there is a get map value let's drag that over ensure it's under the repeat but it doesn't get repeated and our map is music underscore map now for the key we can actually write the room in here and room is an inbuilt variable that will return the name of the current room so we can use that to ensure we're getting the correct map value i'm going to store whatever it pulls out into a variable called music and store it as a temp now what it's pulling out if we go back to our create event is the value here so we're getting either this name or this name depending on which room we're in and this name is the name of the song so if we know the name of the song we can then just play it but we also need to make sure that we're not currently playing it so let's go to audio let's go is audio playing and if audio of music is not playing well then we can play it and we want to make sure we select the loop because we want to loop this so let's test this out press play now we have our song and when we move to another room [Music] we get we get quite a mess so what's happening there is we have both songs playing at once we need to be able to stop the current music when moving to a new room so when we play audio we can store the id of the audio in a variable and we can then use that id to allow us to stop it if it's not already playing so down here where we play our music let's store the id of that into a variable called current music and before we actually play it let's stop playing current music so if we've already been in here before and we've assigned the music we're playing to this variable this will just allow us to stop it before we play the next bit of music so the only thing we need to do is take a copy of this and just create that as a variable so we'll do that in the create event and we'll just create a variable called current music and we'll just set it to zero just so that variable exists so let's test that out and that works much better so that works great but it would be really nice to have the music fade from one song to the next when moving to a new room so if you're a patreon supporter i'll add that as a patreon bonus for this episode and you'll be able to view that bonus video over on the patreon site when that's added it sounds like this [Music] it sounds more professional and just gives the game a nicer feel speaking of patreons i want to thank these legendary patreons who support my channel enabling me to create this free content for you guys dylan jackson box and raven int kay and michael these epic supporters also enable me to do what i do so thank you as well skydevil palm sheldon entp salvatore capolino claypot and dan half and lastly thank you to these rare supporters for their support as well if you would like to learn more about game maker i have a great course over on udemy which is one of the highest rated game maker 2 courses on the site there's a coupon code in the description which offers over 90 off and there's also a 30-day money-back guarantee if you're not happy with the course that's all for this one thanks for joining me i'll talk to you in the next one
Info
Channel: Slyddar
Views: 2,338
Rating: undefined out of 5
Keywords: gamemaker, platform, platformer, drag, drop, dnd, dragndrop, drag n drop, tutorial, peter morgan, one way, oneway, fall, make games, shaun spalding, heartbeast, spalding, yoyo, gms2, gms, advanced, learn, drag and drop, collision, make game, jump on head, enemy ai, horizontal, collisions, coins, collectible, items, objects, slyddar, peter, morgan, 1.4
Id: -nn1vx2P7Nw
Channel Id: undefined
Length: 24min 46sec (1486 seconds)
Published: Sat Sep 19 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.