GameMaker Studio 2: Action RPG Tutorial (Part 5: Initialisation/Pausing)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everybody and welcome to part five this week we're gonna be creating a core game object which we'll call Oh game that's going to manage the game so to speak it's not actually gonna do a whole lot it's going to mostly initialize things so any like settings and things we need to change or run encode right at the very beginning of the game any global variables we need to establish that kind of thing or handle anything matter may be any like debug commands and things like that that we need to put into the game that don't really fit into other isolated or unique manager objects okay that doesn't take a whole lot of time to setup so we're also going to be doing a couple of other things we're going to be bringing in offer style set and sort of decorating our room so it doesn't just look like all these red squares anymore and we're also going to be what's the other thing we're doing oh that's right we're gonna be pausing the game as well I'm gonna be showing you how to get a poor system in nice to have that in early I think I did it actually quite late in my primary production stuff but having that in early is is nice that you can make sure it's uh enveloped everything consistently throughout the project so first of all I'm gonna clean up this room and also create a few new rooms in our room structure and so I'm gonna go to the cold lair first of all and just select this tile and get a nice big brush and just right click to just erase everything we're also gonna delete the player and however from this room as well and what I'm gonna do is I'm gonna rename this room um our parent actually I think I will have the player because we're probably always going to want an instance of the player in every room we make so what this room is gonna do is act as a parent room if you will for any any rooms in our game all that means is we're going to kind of use this room as a template for other rooms to copy from mostly in terms of layer structure okay so what this does is if I have certain layers I know are going to be in every room if I always have an instances lair I always have this coal there were collisions if I always have certain tile layers for throwing tiles I could just add them to the parent room and they'll be copied across into other rooms all right so I'm gonna right click on parent and hit create child and you'll see it like kind of turns it a little tree form and call this our village and we are the name of our first room it's gonna be the the room from the demo is the two little houses in it and you can see it's just made you see we're in our village now might look like we've not actually moved anywhere because it's the same as this it's made a complete copy basically of the other room even down to where the player is positioned and that as I said the main use for this for us is to create a layer structure that we can copy from room to room so if in our village I just go into the collate you can see that each one of these has become kind of highlighted and that's showing that it's basically inheriting that layer perfectly from the parent room whereas if I and and even if I draw here like it's still inheriting because it's just inheriting all the properties of that layer from our parent whereas if I made a new layer you'd see it kind of breaks all of them because they would then all have different debts and so on right anyway let's just clear that up for a second if I come back into our parent and I add another layer in here and just course put it under there another tile layer and just call it a tiles main it's just gonna be one for drawing I mean sort of artwork then I come back into our village you see our village has now got that layer as well also you can see on the coal there if I draw this here and I come back into our parent that doesn't duplicate back in here because that's this is the child and this is the parent okay that's not the only room I'm gonna make I'm actually going to duplicate our parent here as a room outside of this inheritance tree and just call it our in it's short for initialization and drag it right to the top so that's the first room we have a load when we run the game and I'm going to delete a player from this room so it is just this black rectangle but still with our width height and like viewport settings and stuff game resolution and I can go ahead and delete these tile asks and I don't need them in the initialization room this is the room where we're going to put our game object and then our game object is gonna initialize some settings and bring us through to whatever room we want to actually start in which will be our our village room right so we never actually load the our parent room it is just there as a template for other rooms so we'll skip straight from our annette to our village and then from our village to whatever other levels are in our game we never actually go to this room it's just that as a template for our other levels do be careful as you're editing these rooms that you're editing the right ones obviously they all look very alike a phone just you can always just check up there to make sure you're on the correct room okay so just back in the workspace I'm gonna right-click go to resources create sprite and we're gonna bring in the tile set for decorating our village so I'm gonna click import again this is back in our ARPG assets folder with all of our wonderful artwork I'm going to find s tiles for those of you making your own artwork this is I think 16 by 16 tile set as in each tile is 16 by 16 the image can be more at the side she one just is just where all the artwork for the game is going but if you're working with the same resolutions as me then it's sixteen by sixteen tiles make sure the top left one is blank I've not organized this very well for some reason the entire top row is blank it says it's all just kind of a mess but it doesn't really matter too much for me in terms of how I place this stuff I've actually technically got a couple of like a 16 tile like Auto tile set up here but I actually don't really like the way game makers room at a works with sixteen tile or eight tiles my finally quite limiting and Hardees I mostly just place all my cards manually so I don't really bother setting out of it but yeah that's the sprite don't need to do anything with a the origin on collision masculist it just needs to be in got s tiles cuz it's more or less all about tiles the I'm gonna go to tilesets create a tile set and call it T trials just the same really assign the sprite to be s tiles mine by default it's gone 16 by 16 so just make sure that that's correct you see the top left isn't anything and all the tiles fit neatly into those squares all right with that tile layer setup let's come back to our village make sure it's our village as I say they all look quite similar we've got that tiles mean if you haven't made that layer already make sure you go ahead and make it make it in the parent ones so it's inherited and all the others but in our village select that layer select the tile set to bt tiles and then if you go to the room editor tab over here if you don't have that for whatever reason like you accidentally closed it down it'll be a room tile editing file selection window you bring it back it if you accidentally close any of these windows generally they'll be like another thing here depending what editor you're in this is the room editor so there's a room one here and it'll have all the different windows that should be up so you can even bring them back that way okay um but bring this up a time-honoured super zoomed out because there are sixteen by sixteen tired so i have to press control mouse wheel and kind of zoom in and i'm just going to quickly just by clicking and sort of you know clicking and right-clicking to remove i'm just gonna draw in the village all right I think that'll do for now for the base tile they're just one thing I should probably explain I'm also going to add that this obviously sometimes you'll have tiles like I do here that you want to draw above other things so don't be afraid to just add more tile layers and like this tile layer is never going to interact anything game wise and really matter what it's called or how many of them you have so I'm just gonna go into parent and I'm gonna add just another one about here what's called just tiles upper and I'm gonna search would be the exact same tile map and come back into our village and then we've got this one as well which just a unless is place some more tiles but above the layer we currently have okay and just pop some kind of flowers and stuff about place yeah just a handful white I think that looks fine all right so that's our village now a bit easier to distinguish from our other rooms I'm gonna move the player first of all we don't want to standing on this war I'm also gonna change this the change this to like eight by eight or something just so I could shouldn't the grid there just to allow me just snap objects around a little bit easier and then I'm gonna come to the coal at layer and just paint in on the collidable areas okay well that's a good point actually if I come to our parent I need to move this above the other things just so we can actually see it above our art tiles okay that's important to come back here you see that's that's inherited fine it's important we actually need to be able just see it above the art so so we can see what we're doing so I'm just gonna paint and where I want to be collidable suppose we don't want you walking off here we'll just put invisible wall there for now we'll do something about that layer not sure what that and yeah we'll also stop you're walking off it just for now but we'll make that area transition eventually but that's fine for now that's everywhere we can collide with and so that would all work other than the fact we can't actually get to this room because we'll be stuck in our in it at the moment with no way to actually get to this room it would work obviously as well we're gonna eventually put roofs on our buildings as well they're not just gonna look like these empty spaces um but uh we're gonna save that for a future episode because I'm gonna deal with we'll put those on at the same time as I deal with making a/c can have rooms that you don't aren't necessarily room trapped like this one will be a transition we'll go from this to a separate room entirely where we have a shop whereas this one will just be one where we kind of make the roof transparent once you go in and you can kind of see what you're doing on the inside so the two different things so we're gonna leave them for later for now they can just can't look like this which i think is fine all right so now it's about time to actually make that Oh game object to us talking about the the main focus of this actual episode so I'm going to right click on objects hit create object and call it o and game and then a market as persistent that's kind of important also gonna close it's gonna close the room editors that we've got just to close that down yeah so in your market persistent because this object is going to hang around between rooms like you're today of instances of this object will persist between rooms so we make it once in I knit and then it will always exist in every room as long as we have a explicitly destroyer so there's gonna be a few events than this first one's gonna be the create event um let's make the code nice and big I won't necessarily maximize this because we're not we're not gonna be in this code window for very long but later on this will develop into a code window with quite a lot of things and it will be where we do all of our global variables and where we initialize a lot of different things not a whole lot to do right now that needs initializing um just a handful of things really need to set a global for our game paused state so I'll do that global dark game pause equals false and the only other real thing is to go to the next room go to the appropriate room know type room understood go to open bracket room underscore start in all caps which is going to be a macro that I'm going to fight when it comes to macros real quick hache macro room and just go start space and then the name of whatever we want to be the initial room of the game since it doesn't matter anymore it's at the top we we need to know which one we want to skip to and that's gonna be our village all right and then that allows us to easily change that if we ever want to star in a different room to test things out and so on okay back to the workspace now that'll go red those are the only two real things we need in the create event for now I'll put a description in here as well um just feels right and this initialize and Global's class the main thing we're gonna do in here while I'm here as well I may as well support randomized open bracket close bracket semicolon that's a function that will just change the random seed of the game okay just to make sure if you ever do anything in your game and most games of any complexity usually have some element of orangey and then somewhere or other not all but you know the vast majority you probably want to have this somewhere unless you're doing something specific because otherwise every single time you run your game the random results are always gonna be the same and that guarantee is like in you know if you made a game that generated three random numbers and just printed them to the screen and say it came up with twelve thirty 256 every single time you ran it it would come up with twelve thirty-two and fifty six every single time unless you have this randomize function carry out just once and start your game and just to randomize the seed of RNG for thanking all right so that's the create event for now as I said there's not much going on in here but as the project develops a lot more stuff will be getting added to this specifically a lot of global variables and things like that we'll need to Claire and we'll go in here and so on alright next I'm going to add a couple more tiny events first is going to be a key pressed letters our event mostly for us rather than the players will probably remove you know if you want to ship this to players it's good to remember to remove this her before you actually do unless it's a small game you want our to be just a game restart button we're yeah we're literally just gonna have this event restart the game so game underscore restart open bracket close bracket semicolon alright that's just for us just so that when we're running the game we can quickly just press R and restart next one we're gonna add the room start event which is somewhere other other yeah other rooms start and so this event will get carried out every single time a rumor started generally a helpful event in a persistent object so that you know when you go from room to room this is going to happen ever so every time we do like like we're doing here room go to we go to another room and that room is initialized in the game these things will happen okay including when we go to like if we go from that room back to our and it for some reason or to another level and then we come back to our village it'll happen again so every single time a room this startup all right so on room start what we want to do is set the description of this to be layer and management the only function I'm going to carry out in here for now is layer underscore set underscore visible open bracket call in quotation marks comma bolts close brackets gonna come on alright that is going to take that collision layer and set it to be invisible obviously if we have it invisible already that's fine it goes from invisible to invisible but if it's visible it goes from physical to invisible that just lets us keep this on while we're editing and drawing like a collision tiles around and we're toggling it on and off we don't worry I have to worry about going through every single room turning this off every time we want to run the game and see what it looks like we can just leave it on while we're editing very useful and so as you can see just sometimes a lot of code you add is not necessarily about like the end result the game end result of the game that the player is going to see but sometimes your routing code that's essentially just like a framework for you all right I like the scaffolding around your game if you will that allows you to build on it easier all right in the last event we want to add in here for now is the end step events go to step and step again I can't remember why I use the end step specifically for this one but there will be a good reason her in terms of the ordering and stuff I've done with other objects and things later on but the important thing is it's just just like a normal step event just carried out every step and just carried out after all the other step events over other objects in a particular step all right um so the description for this one is pause the game all right this is just gonna be about as pressing like the Escape key to pause the game in fact before I actually do anything more in here while it's coming let's just show you now if I press f5 oh wait nothing happens because we don't have oh game in in the game so go to our net good resources on the instances layer make sure again make sure it's are in it and not our parent and just stick a copy of that object in you'll see it's big question marks it's got a new sprite assigned won't actually draw that not the word drawing this frame anyway it's just gonna be an invisible object and that'll just so the first thing it does when we run the game is it loads are a net loads this object and then our object renders create event and so that's all those variables and then does room go to and sends us to our village here we are and you can see our collision all working fine you can see our collision layer is invisible even though in here it's clearly visible just so you can see everything we're doing so far is working always nice to to check that all right so back in this and stabbed event I will go ahead and maximize this now I will close down those rooms anything we need to do anything more on them and I think this is the last thing we're going to be doing this episode so pausing the game we first of all just want to check if we're pressing the Escape key simple enough if Open bracket keyboard let's go a check I'm just go VK escaped open the braces really quick easy way here to toggle a variable and so you know we've got global game paused which is currently false if I type global got global dog game pause and set it to equal not global dot game pause that will just invert this boolean okay so rather than being like oh if it's false set it to true and if it's true so that the false doing this accomplishes the exact same thing because obviously if that's if game pause is true then nothing is going to return false and if it's false then knotting it is going to return true okay so it just inverts it very useful so we know we've tackled it so we know if we were paused or not anymore and if we know and we know if we were not paused we are now so if global dot game pause what we're gonna do what that means is we've only just paused we've just paused it because we've just we know we've just done this so we know this is the moment we knew that the composed or become on pause so if we've just become paused and I do with all kind of a rare use of that all as a keyword and it'll just select every single instance okay every single instance there every object type that's that's currently active in the game alright so with everything a game pause image speed equals image speed so we're gonna take the image speed of every single instance in the game and we're gonna store it in a variable within that instance so every instance is gonna save its current image speed it's its current animation speed right and then we're just going to set that image speed to equal zero we're just going to stop them animate entirely and have some I know some of you are now thinking or hang on a second that's not quite how a player works but we'll come back for that don't worry about that this is more about like every other object in the game that will be using image view there's currently nothing our player is the only object but later on they'll be plenty of things to animate in to save time we'll probably just use image speed to animate some of the simple ones so it is it's still relevant all right else so if the game has just become unpause then what we can do is with or essentially the opposite image speed equals game paused image speed and we will know that exists because obviously the game isn't starting off paused so will be composed first when we first press escape set that variable up in everything and then when we next press it and we unpause it it'll set the image feed back to the English thing we're not as I say we're not you're gonna see the result of this right away we'll see it in a later episode when we have things to animate with image speed but it's nice to have that all set up and ready now in terms of pausing the player because obviously they've got logic and stuff to carry on and as I say their animation doesn't actually use image speed okay it gets the speed of the the sprite but it just adds that to local frame so what we want to do instead is in a player in the step event we still want to get the players inputs because when we pause we'll probably have like a little pause menu or something I don't know oh you know we still want to be able to gather inputs from the player for any number of different reasons so we'll allow all about to keep running but here when we execute the state machine I'm just gonna wrap this in an if global dot game pause you can either do equals false like that or you can just put the not symbol the start okay which it's the same thing to check what that is false so assuming the game is not paused run the state machine and then the state machine in state furnace oh and that's where we animate sprite so we know that that will pauses mid frame okay that's everything so if I run the game now pressing f5 moving around in here if I press escape you can see that's paused as mid-frame more obvious if I doing a roll like that I see him now just totally paused because we're still running on this code every where is it where's the player yeah we're still running this code every single frame of the moment the game is still running you know you know the game is not totally slept or whatever but so we run this but every time we come to this that's true so we don't execute the state machine and that carries out all the logic of the frame so we're just going to stay in the exact same place because we're not going to move anywhere valleys aren't gonna get it dated in any way and we're not gonna animate in any way it's we're not going to change what frame wrong so effectively totally pause all right and then that's more or less the same way with pause other things throughout the game okay we're just gonna keep wrapping stuff in this that's why I like to set this up early because if I want to do game pause in this way and it's a simple nice effective way to do it honestly can feel a bit like a janky thing to put into a game that's already quite far developed to be like oh do I just wrap everything and every object and like if the game paused is true then don't do anything but I think it's fine I think it's easy to do if you get it in nice and early as well so you don't have to you know be running around making sure you chasing after every object and finding and discovering when you're testing your game that you missed an object or something like that for balls it's easier if you get it in earlier and you just remember to put it in as you make each new object all right so that's pausing the game that's posing Leona's initializing the game I realize that hasn't added that much exciting stuff to the game itself but hey we've got the tile set in now as well so that's nice too thanks for sticking with this that's episode 5 I'll see you guys on episode 6 that was episode 5 episode 6 coming next Friday as per usual and also as per usual thanks to all of my patrons without whom none of this work would exist their names are scrolling past you right now if you want to be one of them you can head over to patreon.com/scishow nsj and get access to behind-the-scenes stuff early access to videos and all that good stuff special thanks in particular to the following Bailey raid Bowser the dog Bertie T cabbage pants jacket on the go Dark Riders zero three one eight do what do be gargoyle Drake huh new Kushi hair om Gen James L Andersen James Higgens Jason Christopher king leo maria celeste de oliveira frailing max m Nathan Wilson pixel mush relentless Rex Rennie dam Robert churches Rove and arlynn run roopinder Schaffer Scott Matthews semion yoga glow Steven Hagen T lesson Travis Womack Tyler Hubbell Victor Stewart Phil Virtanen Sofia flame and Zenon a thank you all ever so much for your support and thank you for watching catch you all next time
Info
Channel: Shaun Spalding
Views: 44,748
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: JwWuZXyTzN0
Channel Id: undefined
Length: 27min 5sec (1625 seconds)
Published: Fri Feb 07 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.