GameMaker Studio 2 - How To: Room Transitions

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome to the next video in our how to game maker series for beginners and today we'll be looking at room transitions or just moving from one room to another previously we have looked at movement and we looked at power ups and as you can see we've got our power up here and we're going to make use of that um oh we're just gonna keep it in there we may make use of it we may not so room transitions uh we can do this a couple of ways one simple way and using an object and one more tricky way using sequences we're going to look at the simple way first and see how we go so let's get started right so i have my example room here room one uh the first thing i'm going to do is duplicate this room so we have two rooms one to transition to now this is the easy way of doing it you could create another room and build it yourself uh but i am going to just duplicate it which kind of makes things a little bit easier and call it room two and open it and we're gonna change it so we know it's room two as opposed to one we'll move the power up here we will get rid of the player because we only need one player the player transitions from room to room and it's the same player object all the time you don't want to have multiple player objects and we have to make the player persistent to do that in fact let's do it right now so open up player object and make it persistent by clicking because oh there we go i've already done it so you need to click the persistent check box there so instances of this object will persist between rooms okay so there will only ever be one instance of the object okay go back to e2 and let's alter it so select your wall object and get painting okay there we go that's room two so don't save that now what we need to do is uh we have to have an object that helps us transition from room to room so we're going to create an exit object so let's do that create sprite create the object super easy let's do it i'm going to resize it you don't have to be this exactly the way i'm doing it so it's good to do your own thing a little bit you know not just copy copy copy because if you copy up a copy your your brain is focused on copying it's not focused on learning at all actually i want this to i'll need to be that size and i want to make it transparent 50 50 and i want to rename the layer base and i want another layer click this one down here and i'm going to call that text and um no that's 300 and i'm going to draw some text on here says exit and because i've done layers i'm going to move it now so get the move control your your selected this layer so you can move this layer exit done now we're going to position the exit object which we don't have so let's create it we're going to create an object not a sprite we're creating an object by a bj ibj underscore exit assign the sprite to it and draw it in room one so the exit's going to be here there and drawing two i think it's going to be here in two right okay getting somewhere now the idea is when our player collides with the exit i can see that you'll understanding what's going to happen here and we get a collision event what we're going to do is in the collision code we're going to say go to room 2 and reposition the player in the right place so for that we need some properties um on the exit object itself and those properties will be created in the create event so when the room's created the object is created and these properties are created hence the create event and they are going to be target room and we're going to set them all to minus one because initially when these variables are created um that is for uh every instance every instance of the exit object whether it's in room one two and three and four we'll get these variables created set to minus one and then we're going to set the values for the particular instance of the object in room one and room two so i have different values for target room and target sorry target x and target y so target x and target y is just where i want the position of the player to be when it transitions into the room so that's the the the uh generic sort of properties set up there but this is now something that you haven't done before you can actually have some creation code run when a particular instance is created so that might be a bit puzzling to you to hear that but what you will understand is that this exit here this exit object here is different from this exit here now when the rim is created and this is created the walls are created the parrots created and the player is created um the create event runs and we'll set up target room target x and target y for this particular exit instance and then we'll be set to minus one however we can run some creation code of this guy here after that this stuff here creation code and we can reset those values because they exist now target room equals room two target x target y whoops uh i don't know what they are let's find out well to find out we go to room two and we say where do we want the player to end up well i'd say about here and the coordinates are down in this corner you'll probably know that already so what's the coordinate here 95 576. so let's go back to that code put it in 95 576 so in plain english that means when i collide we're going to use these variables so what we need to do now well we need to create the same things for this particular instance so let's do that uh obviously we're going to transition to room 1 from room 2 and the coordinates are going to be different so the coordinates are going to be let's just close this into this we're going to come out say here which is 1 180 5 4 1 all right so it's 1 1 80 5 4 1 so we're done the instance code is done so we just need the collision code now so when a player collides so add a collision event on the player to the exit and when it lies we're going to set those um those variables okay i'm going to say should we do this with other uh target room so the other object is the other object that the player collides with i.e the exit and game maker knows that the other object i.e the exit object has target room target target right so now we set it to target what we actually what we do is um room go to target room because these are already set and x equals target x and y equals target y and that should be it so target being target x and type y will be different for every exit instance in every room and when there's a collision the right values will be set to transition into the other room okay so let's give it a go i feel like i've forgotten something um i what i'm gonna do because i experience a few problems i'm going to in no in the collision so the power up we're gonna move oh i moved the sound up here so that's that's okay so i'm not gonna do that because i've done it already i moved the sound up because um the sound was a bit delayed but i think i think the sound is delayed anyway i'm actually going to change the sound source here to my internal speakers i've got a feeling that's an issue all right so let's run it and see what happens all right so there's our guy come in there get the power up oh yes i like that oh look at that oh that's so cool okay maybe not that cool uh the parrot's gone so i only got one jump now will the exit work oh yeah oh no it came out in the wrong place let's see what happens when you go back again that wasn't deliberate i really thought i was coming at the right place uh okay it's kind of completely wrong it seems kind of opposite to where it should be and for some reason i've got two power-ups now [Music] okay so let's go to the instances room one let's check out this creation code again uh so so you want we want to go into appear in room two again target room one that's okay to me did i make i made the player persistent and the power all right this has got nothing to do with it but power is actually persistent take that off so room one september two target x 95 ah so let's check the because that that's looks pretty good let's check the collision a bit ah that's why because we got with so the x and y is not yeah x is it's using the x and y for the of the exit rather than the player so i it's not a good way of doing it i think so what i want to do is just say we can go to other.target name other.targets and other.target y and then x and y refer to the player the players x and y and not the others because i had other wrapping the whole thing so it's referring to the exit section so i reckon i reckon we're good so let's try again and that wasn't deliberate it's just a mistake all right so here we go let's get this power up come on oh yes i love that let's go exit oh yeah perfect okay let's not go let's see if we can jump this oh yeah let's go let's go let's get let's go oh yeah and let's see if we can go back yeah brilliant oh i love it and we get the power-ups and recreated when we get back into the room which is fine it's probably a way of making sure they're not recreated if you get them initially but uh i thought it was making them assistant but i'm not sure i'm not sure that's correct so um that's pretty much it so that's uh that's room transitions the easy way okay so i want to delve into the harder way which means the harder way is just doing more animation type you know so you could do like a fade out or you know like a one of those blind roll things that come from the top and the bottom or you know those the classic powerpoint type transitions um but uh yeah that's for the next subject so hope you enjoyed that we'll see you in the next one
Info
Channel: nexgencodecamp
Views: 36
Rating: undefined out of 5
Keywords:
Id: uMpVJo6Q1O0
Channel Id: undefined
Length: 18min 24sec (1104 seconds)
Published: Thu Nov 18 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.