Creating & Changing Rooms in GameMaker 2.3

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
greetings and welcome my name is aaron craig with let's learn together stick around to the end for details on how you can win my beginner games course so here's going to be our final project that we make i've got a sprite that i can move around and a room that has some tile sets in it and i can hit a invisible warp object over here fade out and into another room with my character still here and everything works exactly as you'd expect i've got a project here and the links to the assets i'm using in this project will also be available in the description down below so i have my skeleton here all this code is pulled directly from the import and animate sprites video nothing else happening there just have the skeleton then i've got the sprites and a tile set set up and you can learn how to do that from my other videos as well then i've got two rooms room start which is right here and room next now creating a room is just like creating all of the other assets in your game you just right click and create room that is such a simple thing i'm not going to spend any more time on that because that's all there is to it now there are some properties of the rooms that we should discuss so the first one is this little home house icon next to your room if you click on it it'll bring up the room order the room order with one of the house on it is the one that will start that's where you begin your game you can change which room by dragging it to the top and now room next is actually the start the name doesn't really matter the house is which one is going to start now there's also a thing called room inheritance which is kind of beyond the scope of this but if you ever wanted to have many rooms that were kind of linked together and had similar layers and everything you could make one room inherit from another let's look at some of the room properties now so i'm just going to be in room start here the very first room i've got i have an instances layer a tiles layer and a background layer these are all contributing to what i actually have inside of here the instances layer is for your objects which somehow my other object got destroyed so i'm going to place my skeleton right there that is where you put all of your objects that actually run code the tiles is for the tile set so if i click on room editor you can see here that i've got a very simple but pretty nice tile set that i've made my rooms with and that's where i put them you want to make sure that the order of these matter because if you put your tiles above your person you can see right here that my skeleton is actually above the tile set but the depth does matter so if i bring that up here now my tile set is actually above my person which you might want for some things but i don't want in this case so the order of these matters because they all have a property called depth right there this depth is 200 this depth is 100 and this depth is zero so if i brought my background up it would actually get rid of everything else which is no good so the depth starts at a higher number which is kind of further away from the screen and the lower number is closer which is going to be important because we're actually going to create an object that has a very low depth when we make our fade so that's something that you've just got to remember if you forget you can always come back and actually look at the depth values here and play around with them the other properties of a room are the actually instance layer properties so when you click on a layer this properties thing will actually change so right now i can see the objects that i have in here if i click on tiles i can choose different tile sets in the x and y offset and you can manually set the depth in here as well if i click on background i get a whole slew of other options where i can actually choose the background color i could stretch this i could horizontal and vertically tile it i could have it be moving if i wanted to i can have an animation speed for the background you can do all of those things so whichever kind of layer you have the properties will change now down here at the bottom are the room settings themselves and there's a lot to cover here and the main one is going to be viewports and cameras which i'm actually going to cover in another video and i actually have a whole series on cameras if you're interested in going more in depth on that you can check that out so the first one here is the width and height of the room itself now a lot of people think the width and height need to be something specific like they need to be a 16x9 or a 4x3 resolution depending on what you're making but it doesn't need to be at all this room size can be anything you want it has no relation to really the camera the view the game window or anything else so if i added a zero to the end of these i could make these really really huge as you can see your room sizes can be essentially as large as you want you could make an entire game in one room i don't think i'd recommend it because the amount of objects that would be inside that one room would become very very large but you absolutely could do it now the thing that does matter when it comes to resolution and scaling is your cameras so you can see this white rectangle here is actually my camera i have enabled viewports which is required then i have set this viewport to visible which is also required and then i've come in and set the camera so this is how much of my room i can see when my game is running and i set it to be 240 by 144 which is about half of the actual room size itself or i guess a little bit less than half since it kind of scales differently but you get my point so this is how much i can actually see but i want it to be centered on my skeleton so we can actually come down here and select an object and set it to obj skeleton and we can have it follow closely enough that when we get 200 pixels to the either side the camera itself will move kind of like i showed in the beginning so now it's on us and it follows us around which is really really cool and i don't have any like logic in here so i could walk over here but i'm pretending that there's a you know invisible wall there that i'm not going in you can also set the speed of the camera but i wouldn't worry about that it's much better to do it through code which you can find on my series on my channel as well now this viewport is really important because by default it's not set to these properties these camera properties aren't set to default either i'm using a very small tile set and sprite so i have maximized you know how much you can see by zooming in quite a bit if you want to play around with these i highly encourage it the camera is how much you can see the viewport is how large the game window is so if i change these to 720 by 480 the actual window for my game suddenly becomes much much smaller i like having it larger i actually have a 1440p monitor so i could make it larger this 1080p is actually not filling up my screen entirely which i think is totally fine but that viewport controls how large your game window is now there are some other options on here such as creation code an instance creation order and a persistent and clear display buffer but for now that's pretty much everything you need to know to get started so that is creating a room and all of the properties inside of it so now let's move on to actually moving between the rooms so the code for this itself is actually very very simple it's just one line it's room go to and then you type in the room you want to go to such as room next and voila that will actually take you to that room if you're not already in it but there's a whole lot more to transitioning rooms than just doing that you have to make sure that certain settings on your object are set you have to put your object where you want it to go and you need to have a good system in place because you're probably going to want to have a lot of warps throughout your game and you do not want to have a different warp object for every single place you can go it will quickly get out of hand and become very difficult to manage so i'm going to show you a really good way to manage that right now so we're going to first create a warp object we're going to call this actually obj warp 2 because this is going to control where we're warping and we need it to have a sprite because we're going to collide with it so i'm just going to click on that press f for fill quickly fill it in spr warp and i'll put that in the warp sprites i'm going to go to room start click on instances if you don't click on the right layer when you try to bring in a warp object or any kind of object it'll tell you that you're not there and it asks if you'd like to create one i don't want to make one even though i apparently clicked yes because i already have an instances layer so i'm going to put this take off the grid i'm going to put this over here so like we kind of go a little bit off screen and then we will warp out now we're going to use variable definitions here and i'm going to show you why and it's actually going to be really really cool and helpful we need three variables so i'm going to click add three times first one is going to be the x position it's going to be an integer then we need a y position and that will also be an integer and then we need a room name now what's really cool here is we can actually select asset and we can limit it to just rooms so you click on that now we can just select the rooms that we want to go to we'll set it to room next in here but we're actually going to change this based on the warp object in our room so if i click on this then i go to variables they pop up here this is super nice because it's more visual and it also is restrictive that you can only set the like a room type instead of mistyping something so i'm going to go ahead and click on edit now i can choose them and i can set where we want to go so i already know i want to go to room next so that one is proper but if i go to room next where do i actually want to appear well i'm leaving from the right which you can see here i'm leaving from the left so i want to appear on the right now to make sure i get the x and y correct i'm going to go ahead and bring in my skeleton here and i want to appear essentially right here so now i can double click on my skeleton and get the 465 and 160 properties that i need so i'll come back in here my exposition is 465 and then 165 yeah oh 160. it's important to get those correct okay so now i've got the properties right so when i click on this once we add the collision code we can actually move to that next room and we'll know where to go so make sure you delete your skeleton because otherwise you'll have some weird glitches because you'll have two players in there and you don't want that so now we've got a way to go there well we know where we're going now we're going to add a collision event with our skeleton and i'm going to add in a very helpful description called collide and we'll set other dot x equal to our x position other dot y equal to our y position and we'll say room go to room name and now we have everything we need to actually move in to the next room so when we click on this we have changed rooms but something funky is happening here there's no skeleton and we're seeing a very strange portion of the sky so the reason for this is when you move rooms everything not marked as persistent this checkbox right here if it's not marked persistent it will not move in to the next room so we have to mark our skeleton as persistent and we're going to want to set up our camera system in the other room to also follow our skeleton otherwise it's going to keep showing us this portion of the sky so let's try that again now we're persistent we click on that and we have moved into this room perfect but we also want to have a kind of fade between the rooms maybe you want to just quickly transition into the next room and that's totally fine it's just nice and simple and some games work better for that but sometimes you also want to have a nice pretty fade because you want to set some things up in the background while your game is like loading the next level now it's not actually loading in the sense of like larger games like full 3d games or aaa games where it actually takes like 30 seconds to load a level i just mean you might want to check and make sure everything is in the right position if you want to set the player somewhere specific based on other data it's best to do that while the screen is black and the player can't see what's going on so we're going to make one more object and this object is going to be called obj warp controller and this is going to control moving between the rooms and fading in and out so no longer is this one actually going to do any of this stuff so i'm actually going to comment all this out instead we're going to create an object and i'm going to give it a variable warp we're going to say instance create depth so we're going to make this at a specific depth because it's going to eventually draw a rectangle or a black fade over the screen so it doesn't matter where we put it just x and y is fine we're going to do depth minus 1000 and then obj warp controller is what we're going to create so let's go into the warp controller and add a create event so we have some data that we need inside of here i'm going to make some variables called new x set it equal to zero new y equals zero new room will be undefined and fade level will equal 0.1 so those are all the variables we need now it's only showing as a warning here because i've got another project open that i'm kind of following and it has these variables in here so it's kind of weird but if you see this warning on all of them don't worry that's just fine let's go back into the warp 2 because now we're actually going to fill in all of that data so i'm going to say warp dot and now we can actually access those variables we just made in that object so new x is going to be equal to our x position variable warp dot new y is equal to y position and warp dot new room is equal to room name so now this warp object is actually just holding the information and it's going to pass it along to the object that actually takes care of it so there we go now let's add a draw event so we're going to draw the fade and the way we're going to do that is by actually just using the function draw rectangle and this can just draw any any rectangle on your screen anywhere you want so we're going to start zero zero and we're just going to do room width and room height now that's not completely necessary since we have a camera we could just draw it inside the camera view itself but for simplicity's sake we're just going to do this it's not any more computational overhead it's just a larger rectangle which is fine we do not want it to be an outline so put false there now there are a few things that we have to set before we do this the first one is actually going to be setting the color which we want to set to black if you want it to be a different color this is where you'd set that now we also want to set the alpha for here because the alpha controls how transparent something is and we want it to slowly fade out and slowly fade in we're going to control how quickly that is by setting the alpha level to our fade level which is the variable we made right there and then lastly we're going to reset the alpha back to one for everything else that's being drawn in our game otherwise we're gonna have some weird glitches show up so make sure that this is here otherwise your skeleton might disappear when you move certain directions at least that's what i was having caused and i it was very weird now we're going to add a step event and this is going to be controlling the fade between where we're at so we already know where we want to go we have a variable called new room so i'm going to say if the room we're in does not equal new room then we're going to increase the fade fade level plus equal 0.01 now the reason for this is the alpha is from 0 to 1. so we can't just increase it by 1 or say fade level plus plus because that will just instantly make it black and we don't want to do that so we're going to increase the fade if we are not in the room we want to go to and if we are in the room then then fade level minus equals 0.0 now when we are about to transition rooms our fade level will be at 1 or greater so i'm just going to say if fade level is greater than or equal to one then we're going to say room go to new room obj skelly dot x equals new x ob scale dot y equals new y so this will only trigger one time because then we're going to transition rooms and then we'll be in this else statement the last thing we need to do is say if fade level is less than or equal to zero then we're going to destroy our warp object or our warp controller because we no longer need it so let's give this a try and see how it works so we can move in here and well that was kind of weird what i mean it worked but it didn't really fade in and out as smoothly as i showed you in the beginning and the reason for that is a couple of things first let's look at our room start we have our warp object here and we have a collision check in here and that's fine and a side note i wouldn't recommend using solids on your objects i recently debugged someone's project where it was super weird but they were both marked as solid and only part of the code was being run sometimes so don't mark them as solid they will still be able to collide if they both have sprites but what's happening is we are colliding and we are continually colliding and to show you that i'm going to say show debug message collide so for as long as we are colliding with this object there we go you see how many collides came up every single time we are colliding we're actually creating a new warp and setting all of this data we don't want that it needs to be a one time event so we need to either only check if there isn't a warp object already made or we need to destroy this object like this now our fades will be a little bit smoother so let's try that out we're not going to have it collide many times so now our fade out looks really nice but the fade in looks terrible so what's going on with that well let's go to our warp controller and look we didn't set this too persistent when you're changing rooms you must set things too persistent so let's try that again click persistent and now the fade level will actually be able to fade out appropriately and there we go we have a nice system that works and feels really really good the last thing i want to mention though is there's actually nothing stopping us from kind of screwing this up so i could keep moving while the fade is going in and out which is not ideal the best solution for this is actually a state machine where you change the player's state to some kind of warp state but if you don't have that you can also just do a check and control all of the movement here so if i say if instance exists obj warp controller is equal to false and i wrap all of this inside of here there we go so now we can only move if there is no warp controller and if there is one we're going to set our sprite index to spr skeleton idle now will always look good and we won't be able to mess it up by moving around at all and there you go that's a final transition with a nice fade and a control with all of these objects and that was quite a bit that we just covered but if you want to see even more stuff from me check out my website let's learn this together in my beginner games course and you can learn everything we just talked about and more while making an awesome top-down shooter game from scratch and if you use the coupon code newbie you'll get 20 off of the course today for a chance to win the course just leave a comment on this video show me your keyboard works and in four weeks i will draw a winner from all of the comments and if you win you can use it for this course or you could use it as a discount for another course including the big bundle i have where you can go from beginner all the way to expert in these three courses talking about game design and development with game maker studio and a shout out to all of the awesome people supporting me over on patreon if you want to see your name on the screen or get other perks like joining my discord or one-on-one training with me check it out in the description down below some links are going to be coming up that you might find useful if you want to keep watching from me but as i always say keep making keep learning and i'll talk to you later [Music] [Music] you
Info
Channel: Let's Learn This Together
Views: 4,572
Rating: undefined out of 5
Keywords: GameMaker Studio, GameMaker Studio 2, GameMaker Studio Tutorial, GameMaker Studio 2 Tutorial, GMS 2, GMS Tutorial, GMS 2 Tutorial, LLTT, Let's Learn This Together, GameMaker 2, GameMaker Projects, gamemaker studio 2.3 tutorial, GMS 2.3, Creating Rooms, Changing Rooms, GameMaker Create Room, GameMaker Change Room, rooms with multiple objects, player character, gamemaker studio 2 tips, learning gamemaker, learn gamemaker studio 2, creating & changing rooms, beginner tutorial
Id: 6lgnW5sr8LU
Channel Id: undefined
Length: 23min 18sec (1398 seconds)
Published: Mon Oct 12 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.