GameMaker Studio 2: Complete Platformer Tutorial (Part 7: Transitions)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everybody welcome back to the platformer series today we're gonna be taking a look at screen transitions so that's how to move on player from one level that we build in one room to another level that we build in another room how we're gonna do this is we're going to create an invisible object that just exists in the background that's also persistent which means that object still exists when we move between rooms and what that object is gonna do is it's basically going to receive commands from a script that we're going to write so whenever we call this script we send a command to this object and that object creates a splack slide transition and then when that transition completes it sends us to a specific target that we decided when we called the command and and then plays a slide transition to bring us in to the name stream so before we get started what I've gone ahead and done is you might remember this level that's the level we were working on before but I've also made a second level okay so I've made in another room exactly the same as the first all the same stuff in it it's got my camera object it's got my player it's got my gun and all that kind of all the enemies and that kind of stuff the walls and dirt so go ahead and make sure you do that quickest way might just be to right-click your first room and hit duplicate and then then you've got all your camera settings and everything are the same and you just need to reposition your enemies and stuff like that but go ahead and make sure you do that okay I've named mine r1 and r2 if you need to just pause the video now go ahead make your second room done that okay cool let's move on the whole reason we have a second room in the first place is so that we have somewhere to actually move to with our transition right the other thing we'll be able to use if we'll be able to use it to restart the game as well so we ought to show you that but we need somewhere to demonstrate that it definitely allows us to move between rooms right so what I've done is I've also left a little gap at the bottom here and every one which is where when we walk there here we're going to place an object here that will detect if we touched it and if we have it'll take control away from the player play our transition and move us to the next room so the first thing I'm gonna do is create our controller object for this okay so I'm gonna right click an object hit create and michaelis o.o transition don't not gonna say any sprite this as i said it's gonna be invisible but make sure you take persistent okay you can even take invisible if you like doesn't really matter cuz there's no sprite but um take persistent which means that if we move between rooms usually when you go from one room to the next it destroys all objects in the current room and creates the new ones in the next room right but if we take persistent on an object it means any instances of an object will just carry on between rooms okay so make sure that this thing is ticked so first of all we're just gonna do some setup in here I'm going to press f12 and gives a bit more space to work with on this I'm gonna add the create event and then I'm also going to maximize this and just so we've got full screen view about code I'll make thanks okay um so a description on the top here she's gonna be size variables modes okay because we need to grab some variables that are determine our screen size they're not really ever gonna change for the sake of this game so I'm just gonna get them in the create event of the transition object and then we don't need to keep getting them and then you'll see what I mean with the mode setup in a second so the first thing I'll do is type W equals display get GUI wit okay open bracket close bracket semicolon nothing in those brackets because it doesn't take any arguments it's just a script Li you can call by itself be juste only to include the brackets and what that does is it gets the width of our GUI one way to think of the GUI is kind of a separate screen layer which we can use to draw like on menus and buttons or anything stack or anything we want to draw on the screen that's not dependent on where the camera is pointing so if you were drawing two lines and the top left of the screen and that kind of thing okay um which is basically what we're doing with our transition right we want to draw that over the screen wherever we are so we're gonna use the GUI for this on the draw GUI event which will see us use a little bit later but we need to get the width of that GUI which is basically the width of our screen any point on okay we could have also used like the camera width and stuff like that the doing the GUI is gonna be more consistent because that's that's the layer that we're gonna actually use to draw our black rectangles over okay that's how we're going to make our slide transition gonna draw some black rectangles and vary their size the next thing I need is the height so type H equals display get GUI on each as you might have guessed again I'm writing a closed bracket semicolon and then the other thing I need is I need half of that value okay because we want to want to win a star rectangle for the top and bottom of the screen to write down and then grow them vertically grow this one down go to the top one down the bottom one up until they reach the middle of the screen so we need to know where the middle of the screen is and we may as well get that now in the Korea event so we don't have to work it out again later that's gonna be H half a to underscore half equals and then hate which we've already got times nor point five okay now I'll divide it by tit or you can you you might divide by two if you want I tend to just write x dot point five so the next thing we're gonna do is a bit new and I'll explain it once I've written it but um we're gonna declare what's called an enum I'm going to write in ohm which you can see turns yellow on bold trans underscore mode which is gonna stand for transition mode okay open curly braket and close curly bracket and in the middle here write the following I'm going to use all counts because constant type stuff I always use all caps off next go to neither will have commas on them that's important over than the last one restart and intro okay and you should see those probably when it updates in a second all turn red yeah so one earth is this um basically one enum is good for what I use them for is for turning things turning basically a set of ordered numbers into English readable words mostly as a coding aid and a coding structure okay so all of these by default you can set them to equal things I could have said like off equal five and then from that point onwards every time I type trans underscore mode dot o basically what I've done is written five in the code okay so you might think well how is this different from just write in a variable well these are very effective for situations where the number never changes okay you unchanged an enum once it's actually been declared they kind of work like a constants in that regard okay there's just numbers that are always a certain thing and never actually a changed or manipulated by anything else if I don't set this to equal five these all get values by default any I should be a semicolon so that should be I should have been a commoner anyway I'm sure you want to Rho equals five if I don't set anything here they'll just be assigned a number and I think it'll work like this will be 0 this will be 1 this will be 2 this will be 3 and this will be 4 and if you're writing something like a state machine or you're writing something with various different modes assigned to it like basically we're gonna have a variable is called the mode and that's going to decide what mode our transition is currently in whether it's turned off or whether it's going to the next room or whether it's restoring or whether it's on currently in the introduction of a room so like it's it's fading as in to the room and so on okay and I could just do this by saying mode equals zero and just remembering with a comment or something zero equals off one equals next and and so on right but that becomes kind of hard to read and hard to remember after a while right I might have to keep looking you know but okay what does mode two mean again and so on whereas if I now write mode trans underscore mode doc intro yeah it's a bit more tight thing but I don't actually have to remember what value this equals I just know that it is a value okay and now we know it's a value that's different to these other ones okay we know it's a unique value I think it would be not one two three four an actual fact but the number four isn't relevant to us in any way all right we know do any maths weather or anything like that we just need it to be unique to these other ones so that we set it to something that done so that when we change mode we know what mode were in we can check to see if mode equals transmode our intro it's basically just a way of turning numbers into English readable words just like variables can be but this ensures that they're all unique from one another and it's good an efficient way of doing it when you've got numbers that never truly change okay okay good I hope that made sense can be tricky to explain now as I say that just a useful thing for um for for helping you code wise okay they don't do things as search they just make your code easier to structure and in some ways easier to remember exactly what it's doing what okay because let me see mode equals trans mode intro we know okay the mode we're in intro mode okay we can read that more easily than reading mode equals zero and be like aw what is what a zero mean which one of these does that mean thanks you know I mean okay the next variables we need to declare are percent percent is going to be between zero and one depending on how complete the black bar this should be of the transition at any time so I went into one we assumed that the whole screen is covered in black and when it's zero we assume that the the bars have faded all the way to the bottom of the screen okay and basically how our step event is gonna work is it's gonna fade off percent between 0 and 1 with a kind of working their like animation easing as well so we're not just gonna add numbers to avoid gonna kind of ease it so it goes really fast and then slows down to a halt goes faster and slows down to a halt whichever way it's going but that's how it's gonna work it's gonna be between 1 and 0 and then the other variable is target okay I'm gonna say it to room for now that that's kind of meaningless what target is gonna be is if we are say in the go-to mode which means we are transitioning from this room into another room we need to know what room were transitioning to okay and that room is gonna be held by this variable and when we call the scripts that we're gonna make a bit late and let's remove this now so we can see all of this script at once when we call a script later that we're gonna write to make us move from one next room to the other what we'll be doing this will be setting the mode that we want to be in and we'll be saying the target room if we need one okay we won't said if we don't need one because the restart will just restart the game go - we'll just next rather we'll just send us to the next room and so on so forth okay but if we want to specify a specific room then we need to know exactly which one we're going to okay so that's all of ourselves done let's right-click now I'm gonna opener blend step okay so I'm gonna add the step event in this one the subscription for this I'm gonna make progress the transition okay because that's what we're gonna do so assuming that we are not in mode off which means we're not doing anything at all means we're either next go to restart our intro progress the percent value appropriately okay and then if percent is 1 or a 0 then we know we probably need to do something okay we do either move to a new room or maybe turn also turn on mode back to on the very first thing we're gonna do is check to see if our mode is not off so if no does not equal funds underscore mode I'm just dot oh okay open a bracket and the next thing we want to do is if Open bracket mode does equal trans mode don't intro okay so if we are in intro mode else close bracket so in here the intro mode means but we want to fade our bars back out okay that means we have come we've arrived in the room that we want to be and remember this object it's persistence that that'll carry across we've arrived in the room that we want to be in so what we're gonna do is fade percent from 1 all the way to 0 otherwise fade our fail percent from 0 all the way to 1 okay how we're gonna do that is a little complex but you don't need to worry too much if you don't understand this you can just if you want to do something simple you could just do something like the scent equals max 0% plus equal plus n plus nor point naught 5 for example it's pretty simple because obviously what that would do is return either the biggest number between either 0 or - sorry know what point 5 so this would either move as slowly toward 0 or if we're below 0 or equal to 0 zero right as it returns whichever is biggest that's the easiest way the man that would create a very smooth transition but like what that would do is it would always move at a constant speed we're gonna do something more complex than that and make it move fast initially and then slow down as it kind of reaches the bottom and the same ways way was when we go when we're leaving a room make it go fast we close quickly close the bars in but then like make the last few pixels take a little bit longer and slow down okay so if you want an easy one feel free to write that and write on the opposite of that in here as well which would be percent equal min one percent plus naught point naught 5 okay if you want to really a much simpler one feel free to write that but now instead of that what we're gonna do is write some more complex maths not really much more just like another max line in here just quite a few brackets involved to keep track of really oh that do things a little bit fancier which I do recommend you doing no word team which we don't understand how it works but if you really want to here's the easier way of doing it feel free to copy that now okay good okay let's do the next one so that's close let's get rid of those two lines that's right at how in the way that actually have some easing behind okay so percent equals max again so zero again so it's still just returning the biggest value between 0 and a reduced version of percent right okay to make sure we approach 0 but don't actually go over 0 under 0 rather percent so itself - just as before max again this time and then in open two pairs of rackets percent divided by 10 or no point naught naught 5 ok and then close all the brackets that you've opened okay sit close that pair and that pair right so what this is returning as if these are going to reduce our percent by 1/10 of the sin so if the scent is one it will reduce it by naught point one that's quite a big chunk that's ten percent of it if it's nor point nine which it would be at that point it will reduce it by naught point naught 9 which is 10% overall annoying so it reduces the amount it's reducing it by constantly so it starts off fairly fast like a tenth of it in a frame and then like less than life and less and less and less okay but we don't want that to continue forever because if it does then we'll never actually reach zero or will only reach zero after a really long time because eventually it will like have a rounding error it will be so so small that it will basically equal zero right but we want to be able to check later if it equals zero so we want to make sure that we do actually reach this value so we've put a limit on how low it can go by saying like the smallest we can possibly move our percent value is null point normal five all right okay or like point at that point five of one percent yeah point five of a percent in then we're going to do a very similar thing in the else statement okay can we do percent equals min one certain length the highest we can ever get is long because it returns the smallest value percent plus max open bracket open bracket hope from bracket so we've got 3 1 minus percent close bracket okay so this is one block divided by 10 close bracket okay so that's another block comma not point normal fight again close bracket close bracket semicolon so this is exactly the same okay and the reason we do 1 minus percent here is because we want 10 percent of the distance that we've got left to go which we got automatically from this because if the scent is 1 then we've got one to go right and if the senate's nor point nine we've gotten or point nine to go right and that's what we want the fraction off but we're and we're going in the other direction we're going from naught to 1 1 minus percent gives us the amount because if we're nor point one we've got nor point nine to go to get to one right in the way we find out is by subtracting percent from one and then divide that by 10 so that's what the extra bracketed section is forward to make sure we do that before we divide by 10 so that's all we actually need to do to make sure that percent moves in the direction that we wanted to okay if percent now at this point down here if the cent equals zero then we know that we need to move from trans mode intro back to trans mode off because we finished we've finished our intro transition okay into the new room but if percent equals one that means we've fully covered the screen with black bars and we need to actually move to the next room and set ourselves in to intro mode to start getting rid of them again okay so how are we gonna do that I'm gonna actually use something new here that we haven't used before but first of all you just if thing I need to say if butts then equals equals one or that's two vertical lines or the or statement if you really want two vertical lines or percent equals zero so if it's either exactly one or exactly zero switch-mode okay so what's a switch statement well a switch statement is very similar to like a lot of if statements because what I could do here is be like oh if mode equal friends mode intro and then if mode equal trans mode don't next and so on and so forth and then do their conditions afterwards but that brings in a lot of problems between like oh what order do you do them in how do you make sure what you've done one don't do a different one and so on whereas a switch sort of handles the forking logic like this all at once and just make sure you only do the one thing that you want to do okay so how a switch works is if I open couple of curly brackets the switch it returns whatever whatever the result is of whatever expression you put in the brackets okay so I've just partly mode in so it's gonna work out what mode equals and then what we can do is we write a number of different cases okay so I could write case trans mode dot intro and then a colon on the end here that's a colon not semi colon open another curly bracket and close the curly bracket and then on the bottom line of that right break semicolon okay break is the thing that makes sure that the case ends properly and we don't accidentally do some of the other cases and stuff as well and just make sure that we do the one thing so under that ones over in that case so that case would go off if mode happened to equal transmode intro if I just can copy and paste this and have case for trans mode next for example with a colon okay then we have a case for if mode happens to equal that then do this instead so it's kind of a multiple fork if statement is a fun way of thinking about it make sure you always include this break statement otherwise you can run into weird problems with several cases going off at once and so on so forth all right and so I am going to include a case for each one of the different transpose so I'll put those in now just so we can see how it looks I'm gonna make this a bit smaller so you can see it all at once that's just a little okay so that's a bit better think imma see a bit clearer because otherwise it could get a bit messy to look at so that's just me about five of these don't know okay so a case with um the resort a colon to open curly bracket one pair of open curly brackets and a break statement on the bottom line okay transmode intro trans mode next trans mode go to little turn red to make sure you got the right word trans mode we start and then we don't actually need one for off because we know already in this whole section our very first thing was that when not in mode off so we don't actually need one and then this is our switch statement so this will do something based on whatever mode that we're currently in okay if we are in the intro mode then all we need to do is stop doing this stuff right which means set ourselves back to mode off so I can just say mode equal transform mode dot oh okay that leaves out the sent at zero just ready to start increasing it the next time we move room but it stops actually increasing or decreasing anymore okay it's just don't need to if we're in trans mode next that means we want to go to the next room okay so the next room is always gonna be the next room in our room order it and however they're ordered in the list in the IDE okay so from room one it'll go to room two if you try and do REME go to you if you try and go to the next room from the second room and there's no room under it you'll get crash okay so you always have to make sure there is a room to go to next if you use this okay so with that mode two equal trans it's called mode doc intro okay set us back to the mode where our I blank bars up and folding again and then room underscore go-to I'm just going next okay and that's the command I mean that will send us to the next room in order okay go to will allow us to go to any room we want so if we're in room two we can go back to room one or if we're in some theoretical if there exists like a bunch of rooms we can go to a specific one that we chosen okay and that's what our target bearer will be used for so again was that mode two equal trans mode dot intro is that's what we'll need in the room that we go to next room go to open bracket target okay you can go to as a command that allows us to move to a specific room where it's next as I said just good take you immediately to the next one and then transmog restart will allow us to restart the whole game okay so game underscore respawn simple as that because they'll end up destroying this object and we'll have to actually make will set all our mode and stuff back to the defaults that are not created then okay so we don't need to worry about changing on mode or anything so that one would just do game restart there and then that's everything in here the last thing when you do is just close our initial it's they with another curly braket like that okay I should get rid of the last little red arrow thing we've got a complete set of code I'll step it on okay the last thing we need to do there is quite a setup you'll noticed in this particular episode before we can actually run the game and see any of this happening I apologize for that let's just saw the nature of how how we've done this one but we will get there pretty soon the next thing we're gonna do is make it so we actually draw these black bars because the moment all we're doing is varying a number between not on one this would work still like it would still send us to the rooms that we want to go to um well actually wouldn't would not written the script to actually you just set these modes and our target and everything yeah but still all this is functional in terms of moving it between rooms but it's not functional in terms of actually drawing the blank bars on the screen for the transition that's what we're gonna do now so that's right click and open event draw GUI okay another description for this one it's gonna be draw blank bars all right it's a pretty simple so if mode does not equal trans underscore mode off because if it does then we don't want to draw anything because we're not doing any kind of transition there's no point wasting rendering time actually going through this stuff even if we were to drawing like rectangles zero zero high and zero width you know like even though it's not the drawing actually ends up resulting in drawing then I think it's a waste of process the time to actually call the command so there's no point doing that if we don't need to but if we do need to draw that color see and black I should explain by the way um I mentioned it earlier but we're using draw GUI for this which as I said draws things to the screen without having to worry about where the camera is okay just draws on the screen of your window itself okay doesn't worry about where in the room you are so when you're drawing a draw doing your sad corner like x0 y0 that will always be the top left of the screen not the top left of the room okay it's very very useful so draw a set color black draw rectangle zero zero as I say the top left of the screen and then W which we know is the width of our GUI or width of our screen which we in the create event okay let me zoom this then yeah see if lyrics have that much to write in this particular event comma assent okay just so you can see what I'm actually doing is because I've not really explained we need the x coordinate and the y corner of the top left of the rectangle which we've given at top left of the screen and then we won the x and y-coordinate by giving it another X&Y coordinate we can draw a rectangle okay between them so the next x and y corner would be the X would be the full width of the screen so we go from the top left to the top right and then in terms of our y-coordinate we go from the top and so zero and then to wherever our percentage decides which should be a percentage between 0 and half our screen hunt for the first rectangle okay so we get that by saying % times H ah okay there goes H 1/2 equals half of our screen height and % is between naught and 1 so not x this would be 0 which means during the ride the top one times it would be like the full the full thing so half of the half the width of this half the height of the screen sorry and nor point 5 would be like a core the a quarter of the height of the screen okay and then the last thing you write in here is whether or not this is just an outline or whether it's a filled rectangle that we want to fill rectangles on the right bolts okay copy that actually I'm not going to copy paste I'll write a whole thing again so we want a second rectangle now that's at the bottom of the screen and drawing its weight up from the bottom okay so William x 0 for the X again the left but we want the bottom left this time so it's 0 H we remember H my create event is the height of our screen okay so 0 hates it right the bomb of the window the next X I'm like Warner we want to be is gonna be basically the far right so width again straightforward and then the height is gonna be between the very bottom of the screen so H and the middle of the screen age half okay so it's gonna be h minus percent times a okay so from the bottom of the screen minus the same value that we've got up here which will bring us from the bottom like zero percent to the middle of the screen at one percent okay and then again comma false bracket semicolon okay and that's that's it that's everything we actually need in here one thing I'll write in here just as a temporary thing so we can see it working when I do is draw a set color see white which that's our drawing color to white draw text 50 and comma string plus step okay so we're just going to draw that percentage to the top left of the screen just so we can see it moving between noir and one all the time again 5050 is kind of just moving this so like the top left plus 50 pixels right and plus 50 pixels down okay so just sort of the top left area of the screen we're just going to draw this text on screen which will just show us how far along is just so we can see it working we'll get rid of this command later so it's all set up now it's all finally set up this object is ready and we've actually done this in kind of a really long way there off like faster ways I could have set this up but what I've done here is that it up to be really quite flexible so that we're gonna write a script now that we can just call whenever we want to initially initialize one of these transitions and say going okay which is really useful and then this object can just carry with us the whole game and we don't have to make loads of different objects like oh transition in Nuuk transition out or transition restart and all that kind of thing we just have one we can just call commands to do all these different things for so hopefully it'll be worth it even though it's you know I've been kind of a long selves getting getting everything we need together okay so let's stuff a bit smaller I'm gonna right-click in scripts and hit create a script okay it's kind of come up in this code tab that's fine I'm gonna call this script slide transition now I don't think we've ever used a script before a script is a chunk of code very much like our events okay so like a step event like a create event okay we write a bunch of code in here but when does that code happen well that code happens whenever we call the script from inside another event so now that I've created slide transition as a script you'll notice if I go into say our step event just randomly at the bottom maybe if I type in slide transition it turns yellow essentially what we've done is we built our own command into game maker it's one way of thinking about it okay that we can provide arguments to and brackets we can get results out of it like Hello equals slide transition and stuff like that you can do all sorts of great things with scripts what we're gonna do is set up a script that basically modifies ode transitions mode and target based on whatever instructions we give the script when we call it okay so I'm gonna do a few comments special comments at the top here triple slash desk which is our common like description one I bet think I've been using that description until now but you can also do that desk which you'll notice I've done in some of the other ones you should show a way of writing it slide slide transition I wrote slight description open bracket mode target room okay I've just written that as the title for this just to show us exactly how this command is gonna work okay when we call it in our other events we're gonna write slide transition and then either and then call the mode that we want to change to and the target room if we want to set one we won't actually have to set one using this you'll be able to just write the command like that but if you write the command like that it will also set a target room okay underneath this I'm gonna write another triple slash and then okay and basically what I'm gonna use this for is to define to autocomplete to get me because autocomplete so you know when you type things like please meaning open bracket and you'll see the bottom here it tells you the different things you want to put in like XY and obj down here by writing our own arguments at the top here we basically decide what that shows at the bottom when we call this command okay so it really is like defining your own custom command so our mode all sounds for argument by the way is the thing that you pass through with the script so you type warm word and then you can type a little description on the int remind you what it does and this one's going to be a sense transition transition mode between next restart and go to okay um and then the next one is gonna be at Hogg Target or Target room I guess whatever sets target room when using the go tube okay because that's the only one we actually need to pass a target room in with so that means now I think I can even call it from inside the script I don't recommend actually doing that but just to demonstrate you needs now see at the bottom slide transition come up with mode and target okay so now the IDE knows that we want those two arguments you don't have to write that in but it's very useful so for yourself alia when you're writing it so you can remind yourself like okay this is what my script needs to function okey doke so what is the script actually going to do doesn't do anything at the moment so what it's gonna do is work with our transition object to change its mode and target so with Oh transition okay we've used the width statement before so we know that that just means that the object that we put in here is what's going to be affected by the four line code okay open curly bracket mode equals argument open square bracket zero close square bracket okay you can also write argument zero and what this is what both of these are currently referring to is the first argument that we pass through okay that's nothing to do with how we've defined it okay by again as I say it's just for the sake of autocomplete the script itself like if I cut it again down like a magician and I pass through a bunch of things like I write hello i target whatever right if I did that then I passed through four arguments okay I pass through hellogoodbye mode and target argument zero would refer to the first one to refer to hello in this case argument one would be goodbye I'm in two mode argument three target okay so this is how we get the arguments out of whatever we passed through okay we tied this green argument zero or argument whatever number okay by typing in the square brackets what that does it allows us to have a optional number of arguments okay if you type on human zero and argument one and stuff into things and then you'll find when you do slide transition your code will expect two arguments okay so you actually absolutely have to provide two arguments oh I would have to provide mode targeting if I try to run the game with say mode just by itself and I included argument one in the script somewhere and it wouldn't let you do it and it'd be like this this this command the script expects two arguments and you only gave it one okay but by using the square brackets version we can provide optional arguments we just have to check to make sure certain arguments actually exist we always want the first one in so I'm not gonna do any check to make sure that we have at least one argument in but we might not always want to provide the second argument we don't need to provide a target room if we're not using the go team mode okay if we're restarting the game where we found the game for just next then we just go to the next one in the room order and so on okay we don't need to define a target room unless we use in the go team mode so what I can do is say if argument underscore count is greater than one argument count returns the number of arguments that we pass through so again in that situation where I wrote hellogoodbye mode and target that would be four okay four arguments pass through even though labeling noises start at number 0 the count returns the total number so if argument count is greater than one that we know we've passed through two arguments right we know we at least have a second argument so we can say the target again in no transition that we're modifying here equals argument open square bracket 1 close square bracket semicolon close okay so now that we've done that we can finally see this in action okay we're gonna say an action very simply thanks to all the setup we've done this is our actually really easy for us to use okay that's the main benefit of having done kind of all this work we've done four different chunks of code but they've ended up leaving us with something very very easy to use now so if I go to our player object and when we have our key press R which currently just restarts the game what I'm gonna do with this event instead where I key press R I don't know if I've ever actually included that in the tutorial or I don't key press R or not I included it so I make it easy to demonstrate things but if if for some reason I never covered that then just go to an event key pressed letters are at this event okay we're gonna have this restart the game using our slide transition so all we do is call the command slide transition you can see even came up there open bracket and it tells of the bomb mode and target well the mode that we want is Frans underscore mode dot we stopped okay and then we don't need a target room so I'm just gonna close it and semicolon now you may have noticed I've used this transmode restart enum outside of transition okay that's the other useful thing about doing using enums okay rather than like using a variable the name things they're global and scope I don't think I actually mentioned that at the time which means I can call them from anywhere in my game once they've been defined once okay I don't even think it matters in terms of code order like I don't think it matters if like some code like if I ran this in a different room or whatever and this code I think it actually gets put in a when it's compiled I'm not sure I don't quote me on that but I think it might work like that but I always tend to just make children create events ok but as I say that global in scope so I can refer to them from anywhere's always equaling these values okay so just by doing slight transition transmode restart that should make our transition work now so if I run the game and I appear here and I'm running around and I can run over here just with somewhat different shoot some of these dudes press on nothing happen which is embarrassingly because of a mistake I always make which is I forgot to put au transition in the room in the flesh this is my most common mistake when using game maker by far I write a ton of code for something I run the game and it doesn't work and I don't know why and the reason is I just the code doesn't exist because I've never put it in the game room so come to your first room first go to let's put it on the player layer again drag in Oh transition will just be another one of these little question marks let's just pop it next to where the camera is so if you keep them all in one place okay we only need it in one room so just in whatever whatever room you're loading first okay if you have an initialized room that's even better let's run the game now try this again again run somewhere else just so it was on whatever end and press R and I so you've noticed that the awkward ending of that clip it still didn't work why didn't it work because I've been even stupider still not only did I forget to put it in the room but I also forgot that you actually have to have visible ticked here I told you earlier doesn't matter you could take a physical off if you wanted it totally does matter so I'm redacting that now ignore that I'm sorry for Eddie what I only watched half of this and for some reason thought that they could have visible detect well hey serve your eye for not watching the full video right yeah totally intentional but if you don't have visible tic basically that all your draw events get skipped I totally forgot that that was a thing so make sure you have visible ticked otherwise I'll black bars won't work okay so now for the third time is a charm ruined the game with visible taking you see the black bars came in there at the start that should have been that should have thrown me and initially right we didn't even have the white number in the corner right you think that white number in the corner that's representing off the scent of the transition was just a debug we put it in just so we could see it when I press are now you can see it climbs towards one and then when it gets to want the game restart and then and then we come back into the room okay so as you see right at the start the game the black bar is already there and it brings us back in one thing you'll notice is it like it does right away like that the moment it hits the middle they just instantly warps then I saw what you might like um I mean it looks okay but you might want to think well maybe I want a little bit of a delay that just like a little bit of a breather a little just a slight pause where the screen is just black for a moment okay just as a pacing thing one very quick kind of hacky waver quick and simple way to do that it's just going to here and where you set min to one here what you can do is say one point you just changed these ones to one point two so change one to one point to that one to one point two there and percent people no point to you there so it goes there just over between going between or one goes between one point two which means the black bars end up actually overlapping each other briefly like you can't see it but they they over they go like a hundred and twenty percent of the distance that they should which means it takes a little bit longer to get there and we spend a little bit of time quite fully black before before I should fading now you can even see the number going up and back to it okay very very simple sort of cheeky way of doing that and hey simple cheeky ways are great as long as they work and they don't screw up anything else okay so that's that the other thing is if you're going to play with that value or these values a lot it's probably better not to write one point two and one point two and one point two in here but to write like something like percent okay or whatever and use a variable and put that in place of all the one point 2's and set that up in your career then there's something you can modify so that you're not always modifying lots of different variables throughout your code okay it's generally not good practice to write in numbers like this but I tend to do that in tutorials because I think it makes it clearer to you what's going on at the time so you can see what numbers we're working with and you can understand a bit better but in reality using things like no boy no no five here and even this divided by ten and so on so forth you should turn as many hard-coded numbers as you can into variables it's always good practice in generally gathered well all of them and you know everyone only does it to a certain degree but do it as much as and you'll find your code much easier to look after okay so the last thing we're gonna do is make it so we can actually move between different Rio I mean we've already made us we can move between new different rooms but that's actually like create a situation in our room where that happens okay and so as I say I have this area in the room head down here that we're going to walk to and when we stand here we're gonna move from this room to this room okay so how we're gonna do that one going to make a new object but uh first of all I want a new sprite I've actually already made it because I sell disco before but I'll delete that and we'll make it again so that's right-clicking sprites think create that's Chris call this s trigger okay so we're just gonna have a like a trigger area or or something like that to set us off let's make it 64 by 64 let's just fill it with just a noxious bright color like pink apologies to the screen right now and let's just draw some text and whites trigger trigger area okay um let's make that like old yeah okay this doesn't have to look great this actually is gonna be invisible so don't worry about how kind of crummy this look it just has to be clear to us in the room edit or what it is and what it's for you can spend as long as you like making it look nice but you're only really doing if your own benefit as your players are never gonna see this okay so yeah that'll do for me um origen middle sensor is fine oh it's really just a throwaway sprite now I'm gonna right-clicking objects hit create I'll call this Oh level and okay that will do set the sprite to be s trigger at the event of a collision with the player okay description for this I'm going to say is - next knot with caps like that and what I'm gonna do is gonna say with O player if open close big this up as well okay so this is when this object collides with the player it has control okay which is a variable that we're gonna put in the player that doesn't exist yet and I'll allow us to switch player input controls on and off because if we start this transition we don't want the player to still be running around and able to do things in the level or maybe you do that's up to you and your game in how you're designing it but we're gonna make it so that we take the control away from the player before all the transition finishes okay so a pretty uh thing a little because we need to go in and actually add this to the player but go ahead and put this in the code view of collision so if the player has control set has control we open curly braket has controls go on and then slide a transition trans mode dot we could use next or go to since this is level ends I suppose it would make sense to send us to the next level so we'll just use next and we won't start in fact we'll use go to just so I can show you using the target and the name of the room we want to go to is r2 so I'll type on two on the end there okay what you could do is set up a thing like this and say like target and then set the target of this in the creation code of the the object in the room editor which I'll show you now actually if I place this yeah we'll put it on the player layer why not let's just resize it just to cover this kind of area here and then double click that and hit creation code you can give a specific instance okay and you can do this with enemies as well I'm like if I could will click on Wally enemies and go to creation code you can give an instance creation code that's different from the other objects and that's how you make things different from one what I could do is I could they target equals and then specify a room and then only this instance of this object would have that variable set okay it's a clever way of being able to make this without having to necessarily make a brand new object for like a level one and level two and level three end and so on so forth right okay so that's let's yeah actually let's do that let's go to wrong one so on the player layer let's select this double click creation code target equals um off to the room we want to go to right and then let's come back to our collision event with a level end well as you say we've got target set in here okay which means our game will crash if a target isn't set so you make sure you actually have that like creation code actually set for each instance alloys your game won't compile but it'll it'll compile it'll let you know I will compile the girl crash when you run into this it's also easy error let you know but make sure you do actually have that target set you could set it to a default value if you wanted and create but it's probably better just to leave it so that you get the crash so that it will tell you what to actually set right but it will basically set our transition mode to go to and then the target room will be whatever we put in that instance creation code which we put our to okay so that will work but we need to go go to our player object and actually set this house control variable ups and there middle click on a player which will bring those two our player code go to step and maximize this it's like step so this whole region knows because we split us into regions before but like our whole region here would get player input I'm gonna wrap this whole thing in if has control okay open bracket and close bracket right at the end here just before we ended that region just on this whole section where we decide what key let Kevon key John B equals okay based on our game pad and keys and all that kind of stuff okay and then wrap an else at the end of here so if we don't have control just set all these to be zero its default values because they need to evil something otherwise our commands later or get confused or they might get stuck like we might have been holding the right arrow key and then we take control away from the player and it thinks the right key is still held because we don't never obey at that so we want to update them to be zero if we don't have control so Q R equals zero the left equals zero and key jump equals zero okay and then the very last thing we'll need to do is just go into our create event we should be up here and just right has control equals oh I shouldn't be zero actually be true even cuz it's just a boolean right which is the same thing we should and we control the really rather than using zero on one you should always use true and false where possible really but a bit late with I know so we're having if has control here I'll just say if it's true does all that if it's false does all this okay simple stuff so now transition object is there and it's in the room we should find now but if I run across into it see these dudes on the wigs why not that's all game right and I walk into this trigger area oh we get a crash because I made another mistake making no on this one this is the mistake episode but a it's fine right a lot of mine so I tend to cut out and redo and rerecord a lot of these mistakes I've decided to leave a few of these bones in because hey it's kind of funny and also it shows you what it looks like when you make mistakes and remind you that everyone makes mistakes that's what I'm going with for being lazy and not removing all these mistakes and editing okay so let's go to our level end object so what what happened there when I crash you might have noticed that book came up it said that it couldn't find target and that's because we're withing the player at the moment so it was looking for the target variable inside the player object not inside of this object so we want to type other dot okay so it's gonna return the target of the other instance in other words the instance that called the with statement which is this insolence okay so it'll get it front where it's actually supposed to while we're here we'll do what I forgot to do as well we're just and visible on this off actually have this one be invisible on collisions will still work you don't need visible tick to have a collision mask and now this time when we run out if I run to the right we run into here control gets removed from this transition happens we get moved to the next level i if I press R it'll Restall the whole game bring us back to the first level again okay so there we have it for a few mistakes in a bit of a bumpy ride we have our transition system okay nice and smooth you can see as well I was just holding you'll just have to trust me I was holding D there I was running to the right constantly but you'll see the like I'll just show you again like the control gets taken away from me because it has controlled variables easy I just very quick because the transition is quick but yeah I wasn't able to actually move around anymore i couldíve my good and still I think and still do that but I wasn't to first about that I just didn't want the player to be able to move around and jump and do stuff while while our transition was happening so that's control that I took away the only other thing I suppose I would suggest is getting rid of this number now so let's go back to oat ran and the draw a GUI section just where we had destroy us a color white and draw at X percent now just get rid of that and press f5 and as you can see that number is now all gone so yeah every now every single time that we actually want to move between two rooms we get the smooth transition effect all we need to do is call this command call slide transition just like it say for my key press are literally one line the mood that we want to use so restart in this case and the targa if we have a target room that we want to go to in the case of o-level end okay simple as that hope you've enjoyed this one despite a couple of the mistakes so hope hope those mistakes were useful I think it's worth leaving them in for once cuz I never usually do and I'll catch you guys on the next part part 8 which will probably be in a couple of weeks usually every other week I know it was a bit of a gap since the last one last because I had a huge video as whatnot my patreon supporters hopefully this time we'll get back into the the once every other week that's my plan it won't always go in plan but that's that's generally what I trying to do with the series I don't know how many parts it'll go well I can't say ahead of time how many parts this is gonna go on for I know the goal it's gonna reach us to have which is why I showed kind of very at the very beginning of this series which is kind of like a complete platform where the menu all these these slide transitions and stuff like that also by drawing text to the screen doing a little text boxes and dialogue and stuff like that just to kind of give you everything you need to do a full platformer game okay and teach you most of the skills you need to then build specific mechanics has always been my goal here I know this one's ramped up a bit in terms of it's done quite a lot of fancy coding but hopefully I'm hoping that I'm building you up with each part and you were able to handle this one okay if not you might just want to just go over a couple of times make sure you understood everything and yeah oh yeah I hope you're getting a lot out of it and I'll see you guys on the next part thanks for watching guys see you next time the people on your screen now are the people that you have to thank for being able to see this video that's without their support on patreon I really wouldn't be able to make this stuff big shout out in particular and in a particular order to Dan in a mule Alex Ray Charles Montgomery Angel Rodriguez Harold Guidry Nathaniel Walsh Louis R Pereira Steven Hagen Jason McMillan Owen Morgan Bowser the dog and John Grimshaw thank you very much for your support if I'm gonna be making videos like this full time I do still need more support on patreon I would love to be able to do this work with no ads and just be able to make free great content for everybody but for that I need your support on patreon to make it happen so please if you like the work that I do and think more of it should exist consider dropping me a dollar to a month over there thank you very much watching I'll catch guys next time
Info
Channel: Shaun Spalding
Views: 180,022
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: x5aTU6pVVZs
Channel Id: undefined
Length: 56min 40sec (3400 seconds)
Published: Fri Oct 06 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.