GameMaker Studio 2: Music Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everybody thanks to a vote by my patreon supporters this week we're gonna be taking a look at music in your games playing music fading from one track to another and just behind lighting background music in general at a basic level the most obvious thing and we'll get this out the way just super quickly because this is something you basically just read in the manual is playing music at all it's very very simple so I've brought in a couple of tracks here around this is from an old project of mine one's kind of like a sad slow Suez theme and the other is kind of a combat theme for the same area so I mean you can have a little listen [Music] that actually started a couple of seconds ahead so it sounded a bit weird or beginning that I forgot to set this back that's and the combat one you get the idea right something you'll notice right away when you're bringing in your own music is that the ID the playback then you might have noticed it a little bit and I thought wow the quality of this files is a bit rubbish there but actually the ID in game makes video to the playback the preview a sound thing like the quality it plays back is really really low and yet like I I don't know how audible it'll be in the video but like there's kind of like a almost a background noise to it like it's being played on a vine or something that's like it's in the background which is a bit weird but it's really only there for previewing and just making sure that this is the correct sound so don't worry too much about that when you actually play the sound in the game it'll absolutely be fine format wise you can bring in WAV mp3 or OGG but you may as well bring in OGG because all sounds get converted to org anyway when the game compiles and it's also generally the smallest sorta format to use as well but it as I say it can bring in a web or an mp3 if you're working with those as well so how do we actually play a sound in the game that's really really straight board you really only need this one line so here's my own music sort of persistent object I'm gonna be working with as an example of having kind of a music controller throughout your game um you can do it any way you want really him but I like to keep all my music stuff just contained in one object that's persistent if I can make things simpler but yeah just to play audio play sound that's the arts all you need it used to be like all the versions of game maker had like establish the difference between music and sound effects the new audio system doesn't do that anymore everything is just a sound right so even though I put an M on the front of these four guys just for my reference to remember this is a background music track or whatever or not a sound effect okay which I might use SN for or SFX or something like that for instead but there is actually no distinction made in gaming studio 2 or any even in one point X anymore um between background music and sound so it's just audio play sound the name of the sound resource not straight forward priority now for your background music this is probably gonna want to be a high number it's completely arbitrary so like how high doesn't really matter but you probably want it higher than all of your sound effects ok what this does is obviously your game can only really be a limit on how many sounds you want playing at once and you can actually set that limit there's a command that sets that I'll probably put it on the screen if I remember the name of it right now the determines the number of sounds gaming can have playing at once and if you ever go over that number like so some too many sounds are playing once a maker will drop sounds it'll stop playing sounds based on their priority and it'll drop the lowest priority sounds first and the highest priority sounds last obviously right so by saying this to a big number it means that you're not gonna have your music stopped suddenly if you've got too many sounds playing you'll probably want to drop something other less important sound effects right and then last a bullish at the boolean true or false are whether or not you want the sound to automatically loop a thing would sound as well as it works pretty separately to everything does it to your game engine if that makes sense it what I mean by that is it doesn't work in tandem with the the framerate and the the step rate of your game okay you'll notice like if your game crashes or something like that your your music might still keep playing while your Wow even while the the error is on the screen right so even while your game is fundamentally paused otherwise the music is still playing like it's an almost a completely disconnected system ok but that's simple that is how you would play a piece of background music in the simplest way possible so I run this it's just giving us and you could kind of it I don't know [Music] so that's how you play that and how would you how do you stop a track and how do you play another track that's also pretty simple if I just go key press space for example just give an example of what I'm something that might trigger say we've moved from one room to the next and we want to stop one track playing and play a different track Audio stop sound you can also use stop all which stops anything playing any music track or playing any sound effects you currently are playing so you've got a long scream sound effect or whatever and you want to cook it off a lot something like that you can use strand stop all the audio stops sound and you name the sound in this case ends sewers which will obviously do nothing if the sound isn't already playing so like it'll see if it's playing if it is it'll it'll stop it from playing right and then if I do audio play sound and combat and now I'm just gonna run the game we'll listen to the first track and then I'll press space and you hear the other one oh oops sorry my bad I haven't actually filled in the rest of this command that's priority a thousand and it's true that [Music] and then if I press space so that's the absolute simplest way to play and to stop music and to change between music now obviously that's a bit limited so let's take a look at what else we can do okay so what do we do if when we want to change between our tracks we want it to be less abrupt than what we've seen so far so we don't want to just stop stop a track and then just start another track what if we want to sort of fade one track out and fade another track in at the same time well it's really easy to do that gaming has a perfect function for this it's called audio sound gain okay in an audio sense I'm working with audio gain you can just think of this volume right that's probably the easiest way to think about it and so by setting our gain we are setting the volume of a given sound now if I open the brackets in between here you can see we take in three arguments again this is the name of the sound so what I'm gonna do is I'm gonna fade out our sewers music okay so and the level that I'm gonna the level argument is what volume you want to fade to with zero being no volume and one being full volume okay so I'm gonna fade from one which is on default to zero okay and then and this is important the last argument provide is time which means which is really really useful because instead of hammering us a repeat this over time in a step event or whatever and like set our volume like a bit a time towards zero this function actually does it all by itself because as I said the audio is disconnected from GameMaker like we you don't control it's not tied to your frame rate so you can't easily control in the step of them that kind of thing whereas we've just got this function we just specify a time but we want it to take in milliseconds to fade from one volume to the next so it'll fade to a volume of zero in milliseconds so we want to have that happen in about two seconds that's gonna be 2000 ms okay so now when we press the spacebar or whenever we whenever whatever happens in the game that you want to make this transition our sound will fade out over two seconds and then we can play our new music so audio plays sound again em combat zero zero no no one zero true rather active gun one zero one a thousand right yeah I'll get it right eventually so a thousand priority again and true we wanted to loop you probably also when want to do something in your step event that suggests like in fact we can go do that now when you're feeding out your time trying to say if audio sound gets game so this will return the volume of a given sound assuming it's playing and soo is less than or equal to 0 right so assuming we've reached zero on that we can then do audio sounds audio is it sounds stop audio stop sound yes alright there we go and sewers I'm not typing or thinking great today so audio stop sound sewers and that'll check to see if our volume is hit 0 we we stop playing yeah why is that important it's it's silent right you can have it keep playing at zero volume if you want and that allows you to do interesting things like you could've actually in the career event play both of these tracks at the same time but just sat ones volume to instantly be 0 and then you could fade between them that way so that then you're always fading at the same like track position if they're the same length track wise that could be a cool way to sync up your music and stuff but by doing that you have to remember that both of those both of those tracks are going to be in memory actively playing at once which is wood yeah you don't want to have like say 50 different audio tracks all playing at once and like fading between them kind of thing right so make sure when you can when you you know when you want to completely stop playing a track make sure you actually stop playing it in the end once you said the point is zero okay that's a good thing to keep in mind that so we've stopped flow with we faded this to zero and then start playing that but we need to feed this in otherwise that's just gonna fade this out but then this will just play abruptly on top so let's do audio sound gain and combat let's fade it to well first of all we've only just started playing it so we want to actually set it to zero rather than fading into anything we can do that just by setting zero zero on the end of here okay the level we want to go to zero and the time is zero so that'll happen instantly okay so we start playing it but we've instantly set the volume to be zero so it's we're not gonna hear anything all right then we do the same command again but this time we're gonna fade to one over 2000 okay so then it's gonna fade this out and by the time that's fully faded out this will be just about fully fade it in okay so let's just listen to that now this is just a strike [Music] now I'm just gonna fade to the next rank by pressing spacebar so you can see that was a much smoother kind of transition between the two another thing you might want to do is have a music track with an intro but also that loops so that you don't want it to actually loop the intro but you wanted to sort of reach a certain point in the track and then always loop back to that point this guy called Pixlr Pope does excellent game maker videos on YouTube he has a video on doing exactly this and he has a really cool interesting method it's worth checking on that video if this is something that interests you I'll put a link to it at the end if I can if I can work out how to put it in the credits I usually put one of my videos alright so check that out it's not something that's interesting to you last of all on this palm I'm just gonna quickly cover how to pause and resume which is also really simple it's just functions built in the handle this for you so I'm going to type if audio is paused and then M come by put that in the creative and this time that's all I'm gonna use and if it is paused then we want to resume which is audio sound Riz no is it audio resume yeah what do you resume sound I always forget the order of weather sometimes it's audio sound something sometimes it's audio something sound and I tend to forget audio resume sound and combat okay and then simply else audio pause sound and combat okay and really as as simple as that and then that allows you to pause the sound and all hold it at that specific point and you'll be able to resume in front of you pressing space so here it is playing and if I press face freezes and if I press base again will resume at that point just a couple more examples there [Music] okay I think you see how it works okay really really straightforward you could also do this manually because there are functions to get the current position of a track you have to be careful with because as I say the audio plays kind of separately from game makers who you don't know on any given step what position you're gonna get whether you know and you can't rely on getting it and saying or if we're exactly at six seconds do this or something like that because if you're at those six at the point which you check you might check out five point seven seconds and then on your next step event you might check up six point one or whatever and you've gone over it right Gus it's separate from the framerate but what you could use it for here if you wanted to build in a manual pause system I can't imagine off the top of my head why you would but you might I don't know too much about all the audio system so that could be a reason you'd want to do that or you could do is use the command it's called audio sound get track position I think audio get position yep so you could get the position of a given track um where about it is if it's playing and you could store that in a variable and then you could just straight up stop the sound right and just remove it from the memory entirely which might be a cleaner way of doing things and then when you want to resume it you can check that variable and you can what you can do is set the track position okay same thing right uh just name the sound at where exactly you want do it by just calling back that variable that you store it in right now as you just saw pause and resume sort of more manually okay which might give you a little bit more control over it up to you anyway that's the basics of sort of handling and playing audio which i think was kind of important to cover before I look too much into how to manage it over the course of a game but in the next part of this video rather than the next video I'm gonna do unless I'm gonna do a follow-up video where we look at audio groups and more how to just sort of manage music throughout your game and so decide like oh if we're in this room play this track in this kind of thing okay so I'll see you guys on that part which will probably be next week I'll see you guys then thanks watching big shadow as always to my patreon supporters without whom I couldn't make any of these awesome videos big shout-out in particular to Dan in a mule Charles Montgomery Harold Guidry Nathaniel Walsh Louis R Pereira Nix lambish Steven Hagen Jason McMillan Owen Morgan Bowser the dog and John Grimshaw thank you very much for your support see you guys next week
Info
Channel: Shaun Spalding
Views: 52,253
Rating: undefined out of 5
Keywords: Game Maker (Video Game Engine), Tutorial, GameMaker Tutorial, GameMaker, Game Development, Indie Games, Tutorial Series, Game Maker Studio, Making Games, How to make games, GameMaker Studio 2, GMS, GMS2
Id: 1bBxWOwfID0
Channel Id: undefined
Length: 16min 53sec (1013 seconds)
Published: Fri Nov 17 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.