Room Transitions | Farming RPG Tutorial: GMS2 [6]

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys so today I want to do room transitions and will also just be importing a new tile assets so that we can work on building up a couple more rooms so before we get started I just have a couple notes firstly with the collisions layer so remember how we were taking great care with the order that we were placing all of our layers so that we would have the correct things drawing over each other well through our collisions they should really be at the very top so that they're drawing over everything else so we can see exactly where we're placing our collisions but then we have of course this problem that especially if we're trying to be really precise with our collisions we can't see what's beneath them and a couple people have pointed this out to me and given me a really good tip that I want to share with you so if we just come into a collision sprite we can change it from being this very opaque Red Square to something that is semi transparent so we can delete this click on this little square here and we'll turn down that alpha and this will make it more transparent so do something about that we'll color that in and if we come back now everything beneath our collision layers alright so now that that's out of the way we can start doing the rune transitions for this view and I just want to note that I've done a little bit of setup for this video I've made a couple other rooms I've made the house the upstairs and just a little blank forest area and we're going to come into these so here is the door for my house I'm going to put a transition here and I'm going to put a transition here for the forest so for the house I brought in some new assets I'll leave a link in the description for that and I'm sure you know how to import assets by now so you would import it here and call it SPR tile interior just look like this and then you would create a tile asset for the interior layer and you would assign it to correct sprite there you would make sure the tiled width in height 32 by 32 instead of 16 by 16 by default and that should do you and you should be able to get started drawing your houses so I just want to note that I have put my house kind of in the middle here as you can see and I've added a background Slayer right here and it's just it's literally just a black square but you do need this you need something here so it could be by color or whatever you want another note and it sounds quite important I really should have mentioned this but the order that you put your rooms in in this little tree is important for what room your game is in a load when you run the game and it's always going to run the groom at the top here so that should be your room zero to make sure that you leave that here it doesn't matter or that you place the other ones in but this one is important so to make these rooms what I do but I just duplicated the farm room and then I would come here and I would delete all of the collisions I would sweep out all of the stuff that I donate so delete that come to the tiles illegal the tile so if you just hit E it will change to the eraser and then we can just erase everything in order layers you would delete all the instances except for maybe the player in the camera will delete all of them and you would keep erasing everything and I was filling in grass right now to do agar and then you can get rid of the stuff that you don't need so for example in my house layers I didn't need those two or three so I just deleted those I didn't need the underground layer and I just kept these so set up a couple rooms like that I'll just show you all of my widths and heights of everything because there is one important thing that is fun to do in games like this so when we change from being outside to going inside a house or something all of these games they kind of zoom in a little bit so what I've done is I have scaled up the camera so in here you can see I've made it 640 by 480 that's the size of this little room and for the camera so instead of being 750 by for 20 I have half that in the house and in the house upstairs to be 375 by 2/10 but most other things are the same a little cute thing that I've done here is with the bed I've added this layer here and if I just hide that so you can see the sheet is still there and that's just so that when the player walks in front of the bed it kind of looks like they're getting into bed very cute but I did need to prevent the player from moving too close to that or they would start clicking through so you might need to put a chest here or something so there's tons of ways to do that and only get more into object depth which we still haven't done we still haven't if the NPC's and stuff are moving in front of them behind each other we haven't really been managing that yet that will come in a later video so we might look at this later again that's just how you would do things like that you might also want to add additional layers if you're adding things to the table or something you might also want to add something like an animated tile so if we come into tile animation and let's add an animation and let's come down to the fire for example and we'll just do so you can set the number of frames you want for your animation you can see they're in special multiples here and that's just the way that it's kind of built to work so we'll just go for four and let's grab here here here and we'll go back there so that kind of loops and we'll get a little fire here I'm just going to turn down FPS here there's a few more in this little spreadsheet so for example I think as a clock up here so we could make this let's say eight and we could make it follow the gong as it to expect and fall so you know how they kind of once they do the upswing they kind of stay there for a bit longer so we can do three on the upswing and then the middle and then three there and back to the middle like that go and if we come back to the farmhouse and we'll go into the actually I'll make another layer l1 objects true and so you can come into the libraries and you can click on the animation here or you can just click on any one of the tiles which is kind of cool because then you can like have multiple fires and they'll all start a different frame so that it looks a little bit more dynamic and you might want to do this with something like torches so if I play it now you can see they're kind of different fires anyway and we'll also add the clock okay so now that all of that prep work is out of the way let's close out of all of these and for now we'll just try and get from the farm room to the forest room and I'm just going to leave that extra room okay so we're going to create a new object and when we collide with this objects we're going to make the room change so I'm going to go over J transitions I'm going to give it just be collision yeah and we're going to have quite a few of these in the room in fact let's just make a new layer for it called this transitions and I'll turn off the collisions lon so we're going to have a couple of these we're going to have one to enter the house I'm going to have one to enter the forest and they're going to want to send us two different rooms so we're going to need different behavior depending on what instance it is and a way to do this is using the creation code from within the room editor so you can see there's a few variables here that are unique to this instance we've got its scale looks we've been scaling it up and this one over here you can see they're different so if we set a variable for example go target room and we'll just set that to minus 1 and actually I just want to do a little thank you shout out to Shaun Spaulding I was watching one of his recent videos and he pointed out that if you just hit f8 you can zoom in and f7 zoom out and make the text a bit bigger so it's a bit easier to read now anyway if we make this variable set it's a minus 1 we can still come in here and then come into the creation code and we can change it for that instance so I can set it this one it's target room is going to be RM forest right so when we step on here we want to go to the forest and this one is RM farm house okay and I'll add one also to the forest room so we can come back oops you've been new Leia transitions to give back to the farm and we'll set this one I get room to be cool fun okay so now we need to do the actual room changing so there's two ways we can kind of do this we need to detect a collision between the player and obj transition now which object do you think we should put the collision checking code so in terms of efficiency if we put it in the transition object and we have maybe five of these in the room they're all going to be running code checking for a collision with the player but if we just put it in the player and that's just that one object checking for occlusion so it's doing five times less work so that's what we're going to put it we're going to come into the player will quit out these rooms just to give us a little space we'll come into the step event and scrolling down to the collisions - right under all of this I'm going to add another one comment it as objects and this is where we're going to put our closing code so here we use the function place meeting to do our collision checking and if you recall what it does is it checks for a collision with another object at a specific XY location and this function is going to return true or false so that if a collision is true then we do this and if it's false then we haven't collided now we're going to use a different function here called instance place and this is very similar to place meeting you can see we still give it an XY location and a collision with an object so we can put XY obj transition as normal but this function doesn't return true or false what it does is it returns an ID or no one so basically what you're doing is asking hey am i colliding with any instance of obj transition at this location if I am give me the ID that I'm colliding with and if I'm not if no obj transition is at that location then it returns no one you're not colliding with anyone so we can save the value that this returns we can go vial inst and just like that we're saving the ID of the obj transition that we're colliding with and we need to do this because when we change our we want to move to the target room of that specific instance right so we have to find a way to get its ID and this will do that for us so now we say if inst so if whatever this is equal to so either an ID or no one so if n is not equal to no one which means it is equal to someone so we have found an obj transition by colliding with so this is the case we want to do a room change so for now let's just write room go to and now we just give it the room that we want to go to so this will be the inst our guest room right remember this operator is saying this variable that belongs to this instance we're going to go to the target room of our instance that should be enough so if we run the game now let's check that's working so let's come over to forest there we go and if we go back there we go it's working so there's still a few more things we have to do you probably notice that we've just fallen right back at the starting location of where we placed the player here it's not like we're appearing right outside the room like you might be expecting and we just we haven't told it to do that so we're going to have to set up some variables so that and also we should do the fading between rooms and I'm going to do that one first so we're actually going to do is going to manage this from within inside the game object the game is going to manage this and it's just going to draw a black box over the screen and I'm going to use the draw GUI event pose because I don't want to draw it over the entire room I just want to draw it over the screen and you can do that using the graphical user interface layer and just as a note this layer is it basically just covers the game window and it's entirely unscaled so if you give it a coordinate from within the room it's not going to match up to the GUI layer which is draw rectangle so we have to give it x1 y1 and this is the coordinate of the rectangle at the top left and x2 y2 which is the bottom right so we want 0 0 X that's at the top of the screen and then these variables are just going to equal the width of the GUI layer and the height and we can get these values using a function and so I'm just going to go into the create event and set up through variables GUI with and GUI height and this is just so that we only have to run the function one time at the start and it will save the GUI width and height there we go and now we can just put these in here GUI width 3 height and 4 outline false we want to completely fill in actually let's make this draw a rectangle color so that we can say draw a black rectangle so and if you're wondering why it's asking for four different colors that's just because you can actually have a kind of multicolored rectangle so if you want to play around with that then you can put in different colors if you like I'm just going to keep it at black so to do the actual fading what we have to do is change the Alpha of this rectangle and we can use that using draw sets alpha and this will set the Alpha of the entire drawer event so we're going to start at zero and then fade up to one then we'll do a room transition and then we'll fade back out from one to zero so we're going to have to set this to a variable because we want to control it so I'm going to call this black alpha we haven't declared this yet but I'm just going to put this in and then we have to be careful we have to remember to set this back when we're done because otherwise the draw alpha is going to stay like this for everything that follows which is not what we want so we want to put that back to one so we'll start the black alpha off at zero because obviously we don't want anything drawing and then what we'll do is we'll be changing this up and down so because the game object is going to be handling this we can come back to the player and we're not going to be doing this anymore so the player isn't going to be initiating the room change but what it will have to do is pass off this variable to the game object because the game object isn't immediately going to change the room it's going to have to fade out first then do the room change and then fade again so it is going to need a way to store the target room of our instance variable so we need to pass this off to the game object so in the game object we need another variable we're going to call it spawn room we'll just set this to minus one by default again and so we need to set this to the transition objects target room so here we're going to go with a game object we're going to set the game object spawn room equal to this instances so kind of hopped into the game objects change one of its variables and set it equal to the instances target room so now it knows what room we want to send it to okay so one other thing we'll set up in here is do transition equal to false so what we'll do is we'll wrap all of this room changing stuff all of this fading and in fading out and if do transition is true so we're only going to be doing this if it's true by default it's off so in the player what we'll do is well when we have our collision we'll also turn that on so do transitions equals true okay and that is all the setup we need for handing off to the game so you can take it from here so we'll come back here so now let's comment a couple sections so this is the drawing the black fade and here I'm going to go handle black fade and room transition now with the fading there's kind of two cases so we're going to have if the room that we're currently in does not equal the spawn room then we haven't done a room transition yet right the current room does not equal the room that we want to change to so in this case we want to be increasing the black alpha so we're going to be fading to black so we're going to go to black alpha plus equals so just a small number because it only goes from zero to one remember the other thing we want to do in this case is check if black alpha is larger than or equal to one so if we hit if we're completely faded in and we just put this greater than just in case it goes over one if we've entirely faded in then it's time to do our room transition so we go room go to the spawn room so that's that stepped-on but if our room does equal the current spawn room then we know that we've completed the room change and it's time to fade back out so we go else black alpha minus equal 0.1 and once it's completely done when the black alpha is less than or equal to zero then we can turn off this entire code we can stop drawing everything because they're totally done and we can turn off do transition okay so that should be if let's run the game and see if we're getting that fading we go and the that's working so the next thing we'll do is we'll fix that problem of the spawning locations so we're transitioning like that and we just pop right back here we're going to need to set up two more variables a target X and target Y just on the player so in this in our transitions will call this target X and target y and this is just for the people object of course we'll have to change these in all of our individual objects so this will take a bit of playing around because you'll have to check exactly where you want player to spawn so if we come into the forest and you can take advantage of this little thing right here so this is sort of tracking the coordinates of the mouse in the room so we can say that we want the players to be about here when it spawns we don't want to be right on top of the objects because as soon as we enter the room it's going to collide with this again and then pop right back so we want it to be about here for now 65 370 I'm going to put and for this one will spawn about nine seventy four thirty you okay so that set up what we still need to pass this off to the game object so in the game object we're going to set up a spawn X and spawn flight and we're going to add an event this is going to be the room start to whenever we're starting a room we're starting a new room what we're going to do is move the player to spawn X and so on why but remember when we first start the game our default values are just going to be these and we're going to end up supporting the player over at zero zero and that's all what we want so we're going to say if the spawn room is minus 1 if we haven't done any transitions yet then just exit and don't do this okay so that's setup but we've got the spawn X and spawn line for the game and we've got target X and target Y for the transition but they're not talking to each other yet so what we need to do is come into the player because that is the actual object that is mediating all of this and is detecting the collisions and we have to pass these values off just like we did with the room so we're going to change the game's spawn X to equal our obj transitions target X and same the y why actually one thing that we should add is we only want to do this once as soon as we collide we don't want to keep turning this on we might get some problems so I'm just going to say if if we're not already doing a transition then you can go ahead and do this but if it's halfway through a transition or something we might get some odd behavior if we try and start another one so we'll just prevent that and say you can only do it if I'm not already doing a transition okay let's have a look okay so we'll come over here to go okay so that's working the next thing we're going to do is handle where the player is facing when it pops into another room so if we go in here you can see that it automatically is starting and looking to the left we're going to set it up so that we can control the direction that the player is facing and have it facing the correct kind of way so this direction thing not only can we make sure that we pop the player into the room so that they're facing the correct direction we'll also make it so that the transition objects require the player to be walking in a certain direction to actually change rooms and this is so that if we're just walking over the transition object but we're not kind of going into the door you'll still allow us to do that and also that so that we can spawn the player directly onto the transition object without it automatically just going to the next room the first thing I want to do is come into the game object and I'm going to set up variables for us to use for direction this is going to be we're going to use a thing called an enumerator so an enumerator is kind of like a global variable which means it can be used anywhere and it kind of creates a datatype so we're going to call this derp and then we're going to come in here this is how we type it and we can set up different variables here and I'm going to have write but I'm going to set this to be 0 up going to be 90 left just going to equal 180 and down is going to equal to 70 and I'm doing this that we can kind of set up an analogue to the actual direction value in game maker so if I just bring up the documentation for this this is how it treats direction so with zero being right now you're diluting up and it goes around like this and some of you might remember this from fun times at school doing the unit circle so now that we've declared it in the game object we can actually use this even outside of the game object itself so enumerators like I said before they have global scope which means you can use it anywhere so the way to access this is you would write stir dots and then a direction and that would be equal to zero so now let's come over to obj transition and we're going to set up two more variables we're going to have player facing the four and this is going to be the direction that the transition object wants the player to be heading in for a transition to actually occur so we want the player to be facing a particular direction before we transition and I'm just input minus one as a default value and we'll change this again in the particular instances so after and we will have to come into our instances and we'll have to update it so let's have a thinks of this one this one's going to require the player to be heading to the right and in the forest room we also wanted to come out facing right so for this instance they're going to be the same so we write the stop right Thur dot right okay and well then the one in the forest is going to be the opposite we're gonna want left you can imagine there might be cases where these are going to be different so for example if I come into my house if I had a transition object right here so that's going to want the player to be moving upwards and then when I actually come upstairs I'm going to come out here so I'm going to be wanting to face to the left so that's a case where they would have to be different anyway we're just working with the simple case for now so just like before with this for an X we're going to have to pass these values off to an analog in the game and I'm just gonna call this spawn player facing will start off at -1 again could we'll be updating this when we have a transition in the room start this is where we're going to want to shift the players position so actually we're going to have another value in the player and we're going to call this facing and I'll just have a 0 for now and in a step event we're going to add some codes that we can get what direction that we're facing the get Direction player is facing so we'll have to handle this in two cases for left and right and up and down so we'll go if move X is not equal to zero and I've put this here because it's right after we get the intended movement but before we do the collisions so if we're moving left or right and I'm going to use another switch statement so we're going to switch the sign of move X in the case that it's equal to one so if we remember sine is getting if the move X is negative positive so it's going to return 1 or minus 1 so in the case of its 1 we're going to change facing to equal the rice and break and in the case that it is minus 1 then facing is going to equal left and we'll copy that else if Y and we'll change all these so remember so the one to move Y is if I'm moving down because we start the origin at the top of the screen so in the case that it's one we're going downwards and up ok so this will change our facing variable to be equal to the direction right left down or up which is actually 0 90 180 270 and then I'm going to say else so if we're not moving at all I'm going to say facing equals minus 1 ok and now we're going to change into the drawer event we're going to alter this here so remember this is the thing that was updating the direction of our character to draw so for example if I just click here remember we were getting this frame moving left down right and up and it would depend on how far down we are on the sheet so now instead of updating the frames depending on I'll move X variable we're going to update it depending on the facing variable so we're going to do this as a switch statement again so we're going to switch facing okay so we're just going to copy this and we're going to put it in here and we'll just make our changes we're going to say in the case that facing is equal to letter and we're changing the y frame to be bad and we'll keep going down like that so right up and down and finally if it's negative one so remember this was when we weren't moving it was setting the frame to the idle just going to tab deserver okay and I'll add the brakes in here okay so we can get rid of all that now this is just shifting our system over to include our facing so now our game objects can modify our facing variable when we start up the room so in our game objects we can tell the player to set its facing to be equal to this variable here and again when it going to need to pass this off so to come into the player into the step event and set the games value to equal the instances player facing after that was the direction that we wanted the player to be in after the room transition so now here with the with the actual collision we have to say if we're not facing the correct direction we're not actually going to go ahead and do this transition so we're only going to do all of this let's say if inst is not equal to no one I'm going to add another condition we're going to say and so if it's checking this and this passes it's going to go ahead and check this other condition here so and the direction that we're facing is equal to the direction that our transitional objects wants us to face then we'll go ahead and do all that okay I think that's everything but if we run the game now it's not actually going to work and it took me a little bit of time to puzzle this out I'm going to go through it with you guys because it requires an understanding of the event order but so if you notice it's not working I should be popping out facing right but it's still facing laughs and the reason is it so if you picture the order of all of our events so if the game object at the very side of the room is changing the direction that the player is facing to be equal to this so this is at the very side of the room but then we still have all the step events in the drawer events to run so there is a step event in between here and the actual drawing of the player in the correct direction and this is going to give the player time to change this variable and it's exactly what it's going to do yeah because if we're not moving then it's going to change facing to be minus 1 which means once we get to here it's going to follow this and set the X frame and it's not going to set the Y frame and the y frame is what we need to change for the direction so this is the actual thing that's doing the work so what we need to do is run this little thing here at the room start so we'll grab this go into the game and then we'll just go with obj player and we'll have it run its little switch statement okay now we should be good there we go and just to make sure I'm just going to change one after to be up you okay so if I'm coming at it from another direction if I move over it it shouldn't do the room transition so let's get out try there we go and if I go right your transitions and there we go we're also facing upwards just like we told it to and that means we're done I'll leave you to setup the rest of the project as you want and the rest of the obj transitions so now that we have the room transition system set up we finally have everything in place to start doing our crop system and I'm really excited about this because this is probably the most important part of the series we're doing a farming RPG so obviously the crop system is a very important mechanic and I'll probably be doing this over multiple videos because there's a lot to go through and I want to make sure that you guys understand everything we're doing and I'm explaining all of the concepts especially because we're going to be using data structures which often scares people away a little bit but don't worry I'm going to walk you through everything so until then take care and I'll see you next time
Info
Channel: FriendlyCosmonaut
Views: 44,950
Rating: undefined out of 5
Keywords: farming rpg tutorial, farming rpg tutorial gamemaker, rpg tutorial gamemaker, rpg tutorial, friendly cosmonaut, friendly cosmonaut farming tutorial, friendly cosmonaut rpg tutorial, game maker studio 2, gms2, gamemaker, gamemaker room transitions, room transitions gamemaker studio 2, room transitions gms2, gms2 tutorial
Id: hB8jBj6itUA
Channel Id: undefined
Length: 32min 26sec (1946 seconds)
Published: Wed Aug 02 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.