GameMaker Studio 2: Audio groups & Volume sliders

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
how everybody and welcome to part two of my little two-part music tutorial this time we're gonna be looking at audio groups and volume management so how to manage the volume of a group of sounds and so like your music separate from your sound effects and so on that's quite useful thing to be able to do so what our audio group's audio groups are something you can access through the Tools menu if you go to audio groups that'll bring up and by default in your project if you have a bunch of sounds this group will probably be full of stuff it's audio group under school at the fault and that group gets loaded into memory automatically whenever you run your game that's why you're able to just put a sound into your game and then just play it with audio play sound normally though if you have your sound in a specific audio group so I of two I've named an Ag music and a GSI thanks the sound effects if you have a specific audio group for a specific sound you have to load them in manually okay that's cool because it allows you to control exactly what's in memory at any given time so you don't just have every sound that you have in your game loaded into memory at once because you know sounds can actually get pretty beefy and file size so on it's worth keeping control if what's loaded when but that's not the only advantage to audio groups and the main thing that we're going to be looking at today is that what you can do is you can actually manipulate the gain that's the volume of an entire audio group so you can chip set the volume of like all of your sound effects and all of your music and whatever are the various categories of sounds that you have okay that's really useful you know most commercial games give you the option to change their the volume of say your music and your dialogue and your sound effects and this is a way that you can do that so I've assigned my various sounds here my four music tracks into this audio group just fire this audio groups menu which you can do just by clicking add resource and pick one to add and it'll put it in and the same for my sound effects but you can also add them from the sound editor itself so if I go get any given one of these and mountain for example this music track you could just see audio group of the bomb just got a drop down menu you can just select which all your group you want to put it in it's actually create a new audio grupo Gatti's this this menu of here okay so as I said when you put stuff in specific audio groups other than your audio group underscore default you have to you have to load those in manually before you're able to actually play those sound effects you can do other things with them like you can set up again and stuff like that but you can't play a sound effect unless adoro music track unless it's actually loaded into memory so how on earth we do that well if I go to my own music object vocals they're just kind of handling everything in this part and the create event I just simply used this line here Audio underscore group underscore load and then the name of the audio group use the audio group shows our bread game make it recognizes it as a thing but that doesn't happen instantly so you can't just do this and then instantly run like audio sound play underneath okay that won't work so audio play sound I think of this because you don't know when this is actually going to finish or how long it's gonna finish and it happens asynchronously I mean it's just like not at the same time as the rest of your game okay so how do we know when this is finished well when an audio group finishes loading it triggers an event okay it triggers one of these and it's called the async save load event so asynchronous save load this one here okay and you see I've got that added here with the description sounds loaded and I check to see because I when this events triggered I don't know if it's because of this audio group loading or this audio group loading or maybe something else using that async event right so we have to check to see still if the audio group itself is loaded when this event got triggered and if it is do whatever I want to do so if my music is loaded I actually start playing a track based on music playing I've got a little variable system and some arrays set up to sort of control the four tracks and crossfade between them and I said control to be true which is a variable used to control whether or not I change I can check and change volume and we'll get to that in a bit the sound effects are just variable so that I know I can check later whenever I want to play sound effects to make sure that they're actually loaded in memory before trying to okay simple as that so if setting this up I actually have a volume slider I have a couple of these that I literally just got my face on them and I just used them to drag drag of button around on a bar how I do all that stuff and like dragging it back and forth isn't too important for this video if you're one of my patreon suppose you'll get the source code for this so yeah we ought to kind of look at that if it's interesting to you but I haven't coded that super well or specifically for this tutorial the main thing that's important is here okay so based on my the exposition of this this handle on a bar which you'll see in a minute is just like a little button on a bar by drag back and forth to change volume with our music I set music volume a specific variable for how loud I want any music playing to be to be a thing based on the exposition of this okay so that's just setting a variable called music volume and then I use that variable to do audio group set gain okay and this works exactly like the audio sound gets that gain done audio sound gain rather and that you can set specific volume and also set it over a specific point in time or so specific a specific amount of time sorry so you can fade it if you really wanted to but on here I'm just sending it immediately to whatever volume it needs to be okay so let's see how that actually works really so if I run the game you can hear music already playing now if I drag my face down here that's gone really quite I don't know if you like Miller here in the video still now but you can see down here look where I could I'm showing the gain of all these different sound effects you can see all the music ones that are in the audio group AG music of all had they game changed tune or point 10 okay and I've got a sound effects one here because I can play random sound effects those are all just sounds from random blood and diary games but I can also change that you can even still hear those but you get the idea right okay so what I can also do in this games they can crossfade between the tracks so if I press space you can see the games changing there you'll notice I turn everything gray while I'm doing that because an important thing to know is that when I'm changing the gain of the audio group that's not a very I'm not changing a variable specific to the audio group I'm actually just changing the gain of every sound that's inside it okay so that will overwrite the meet understand so that will overwrite any gain changes that you've done over them okay so if oh you faded a sound out to zero or whatever and then you say using music volume to nor point to or whatever that's going to set everything so what you've got to do is be careful to make sure you stop playing sounds when you're cross fading between them okay so you'll notice when I crossfade if I turn this back up watch what happens so I'm on em puzzle I want to go to em million so that might have been difficult spot I don't know but what I did is essentially I set my games to whatever they should have been so I'm puzzle was the one that was playing so I told that to fade towards zero I'm night old and mountain to fade to set itself to zero and then start playing and fade itself to the given volume okay because otherwise its gain was already at whatever volume right there all at that and then when I when I was finished with that I gave control back to the player because then all will be a correct gain again okay when when and puzzle hit zero I stopped it playing anymore okay so you can't do that thing that I showed in the previous tutorial where you play two music tracks at once and just use their gain to decide kind of whether or not they're playing or not okay if you're gonna set volume using audio groups then you want to make sure that you're really only playing the one track at a time if you need tracks to still be in sync and you wanted to accomplish that there's a thing called audio sync groups that will allow you to do that may or may not explore that and another tutorial at a later date but that allows you to have multiple tracks that play and stay in sync all the time but you can like pause and stop and move between them and so on so you can still use this source system okay so just in case you didn't understand any of what I just said about controlling the game and making it so you can't change the volume while you're fading between tracks because if I was able to do that while in the middle of failure track that would interrupt everything so that's why I lock it out you'd want to avoid the player ever being able to do that so if you're in the middle of a crossfade or something like that you probably don't want the player to be able to pause the game go to the menu and change music volumes that'll screw things up so yeah it's the thing to bear in mind let's just take a look at how exactly that works so if I go to music now and go to I think the step event yeah so down here where I just have keyboard check pressed bass when you place the spacebar to do a crossfade here's what I do so I set it so you can I control the Falls and that's what allows me to actually change the volume with the sliders so is if that's not true then I can't do any any volume changing I find the track that I want to move to then I set that track playing I set its game to be zero in theory I should probably do that the other way around but it happens so instantaneously you're never gonna actually hear a bit of it and then and then have it fade to zero I don't think right then I tell it to fade from zero to the target music volume whatever our current music volume is and I tell music belying are currently playing track to fade toward zero okay and then down here if a fades complete in other words the music playing has faded all the way to zero and and we don't currently have control so that means we must be doing a crossfade stop the current sound from playing even though it's playing at gain zero need to stop it from playing so that we can set its gain back and not have them both be playing at once we need to properly stop it playing music playing changes change the track that were actually playing in the variable anyway because it's already actually playing audio set group gain and then set a slap the volume of the audio group back to whatever the music volume should be and then return control for the player okay that's more or less how it works pretty straight forward and it's a really simple way of getting going with a volume control system which could otherwise be quite complicated so it's a good way to use audio group audio groups and it's generally good practice to use all your groups anyway just to control what's in your memory at any given time hope that was useful this demo and all that code in it like I've only really gone through the relevant stuff but all the stuff like the the actual sliders and that kind of process and how you control that kind of thing I might cover that stuff in another like UI base tutorial that's a completely different topic but the source code is available for my $5 plus patreon supporters so if you are one of those people you can go check that out on my patreon page thanks for watching I'll catch guys next week probably on part of the platformer series all right so you guys then a huge thanks as always to my patreon supporters that's the people who keep me going keep me doing all this good stuff special showers in particular to Dan in a mule Charles Montgomery Harold Guidry Nathaniel Walsh Louis R Pereira Nick slavish Stephen Hagen Jason McMillan Oh and Morgan Bowser the dog and John Grimshaw thank you very much all of you for your continued support I'll catch you guys next week
Info
Channel: Shaun Spalding
Views: 16,650
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: xvtbgZ3-h0k
Channel Id: undefined
Length: 12min 29sec (749 seconds)
Published: Fri Nov 24 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.