Gamemaker DND Platformer Tutorial - #1 Movement

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
are you interested in using Gamemakers drag-and-drop to make a platformer game like this do you want to know how to add animated characters and enemies all within drag-and-drop while keep watching and I'll show you how you can do it g'day I'm Peter and I run game maker courses on udemy they are aimed at beginners but they were also in GML game makers custom language also uses on the yo-yo forums and quite a lot of people ask for assistance on how to do things in drag-and-drop well today I'll be starting a series on how you can use drag-and-drop to create a platformer we'll learn how to build some efficient code to produce a platformer that initially does this but in a few more steps I'll show you how it can then look like this now this has pixel-perfect collisions deceleration for the player as well as various sprites for each character so let's get started now after you've installed either the full version or the trial version of game maker you'll be presented with this start page so we want to click on new and we want to go to drag and drop so you're now looking for a file or name of what you're going to call it I'm just going to call mine tutorial and press save and the project will then load so the first thing I'm going to do is go up to game options and I'm going to set the game's frames per second to 60 now yours might already be 60 and that's fine so the frames per second means how many times game maker will run the code that you're entering per second so our code is going to run at 60 times a second so press ok so before we start I want it to give you a quick overview of the workspace you can see that there are these tabs that can be dragged around and they can be docked or undocked they can be put onto the side and they can be put into the bottom and they can be moved around to customize how game maker looks you can also press f12 and that will hide them at the moment and you can also press this little tab on the side and that will show them so for now what I want to do is right-click on sprites and say create sprite now a sprite is the graphics that you will see on the screen so when you have a player character the sprite is just the graphics that is used to display that object so let's create a sprite for now and I'm going to call it s for sprite underscore player now you can't have spaces in the names so I do like to use an underscore for a space I'm going to change the size and you can do that here and I'm going to set mine to 32 by 32 and then I'm going to click on edit image and now we need to create our player sprite so if I hold down ctrl and shift and use a wheel Mouse I can zoom in and out you can also hold down the middle mouse and you can scroll around or pan around so I'm just going to choose a blue color I'm going to choose the paint fill tool and fill it in blue and you can see that this section on the left is to the left Mouse this is for the right Mouse if I choose a paintbrush tool then I can use my right mouse and I can draw a knife or a player a mature amount now you can also fill in if you like and fill in your the left or right Mouse if you make a mistake or change a color you can just right over it so there's my player I'm doing a face so that we know the which way the player is facing when we actually implement it in the game now press ctrl + Shift + will mouse and zoom on in now this crosshair is the origin of sprite so I want the center to be the middle center I'm going to put it right there so now we can close that and we can create an object to represent this sprite so right click on objects got a create object on a call mine o underscore player and I'm going to assign the sprite that we created now each object can hold its own variables I'm going to create a couple of variables for this one under variable definitions I'm going to click the little three dots I'm going to go to add and I'm going to create a variable called walk under school SPD standing for speed I'm going to set the value to three so our player is going to have a walk speed of three and I'm going to add another one and we're going to call this hate SP and that stands for horizontal speed I'm going to set that to zero initially so I can close that down so we can tell our object what to do by creating events so I'm going to go here I'm going to create a step event now step event runs every step of the game and if you remember we're running our game at 60 frames per second so 60 steps per second so the code in here will run 60 times a second now we can put code to run in the step event by combining the code blocks on the right so we drag and drop what we want the object to do so the first thing I want to do is have the object listen for any input from the player is the player pressing the right key or are they placing the left key so if we go down we can look at mouse and keyboard and one called F key down we drag that over now because it's an ear for asking a question if the key is down we want something to happen and that's something to happen we want to place over here if the keys not down then we place the code below it and it'll keep doing whatever the next step is so let's change the key to write and if the key is down let's go up here and let's choose the assign variable block and I'm going to drag it and put it on the side you don't want it down here we want it here because that means that the key is down it will run what's in this code block and what I want to do if the keys down is to change our HSP variable how horizontal speed variable and I want to set it to walk speed so whenever right key is pressed HSP will always equal walk speed and that'll enable the character to move to the right now I also want to add one for key left now remember this side here is if the statement is true this is if it's not so we want to go and get the key down again so I want to drag this and I want to put it not over here not down here but under the F key down it means after it finishes with this it will then process the next one so we want to say if key left and once again we can drag across the assigned variable and we want to put it on the right here because that's saying if the key is down then we want to run what we have in this box once again we want to set our HSP but this time we don't want to set it just to walk speed because a positive value for HSP indicates we're moving to the right a negative value will indicate we're moving to the left so we need to change this to negative walk speed now before we can test this out we need to add a player to the game and game maker represent your game window as a room so rooms is what we use to drag our objects onto to show the game so let's drag the player and let's put them in the room and let's go up to the run button here you can also press f5 as a shortcut and we'll see if we can move our player so I press left or right I'm not getting any movement and the reason is that even though we've set that up we're not doing anything with this HSP variable the game is not being told to then use that to move the xvalue of the player so let's go and assign one more variable I'll put it under here and what we want to do is assign that HSP value to whatever our exposition is so our X is going to be assigned our hate SP now if I leave it like that the x value will be given the value of h SP every time we don't want that we want it to be added on to the value of x and if we click the relative button that will add this value to this every time so once again let's run that and we'll see if we can get the plan moving so now when I press left and right we do move you'll notice one thing though we don't actually stop and that's because our haters p-value is always set it never goes back to zero we want it to slow down over time though so let's go back to our variable definitions let's add a new one and I'm going to call this drag I'm going to set it to 0.9 now we'll use drag to slow down the player so let's drag another assigned variable and right before we're setting it to our X let's change the HSP and this time what we'll do is we'll say HSP times drag and that way we're getting 90% of the HSP per step so if we run that now we should see that our player will slow down so one press made you move and we get a little bit of a slowdown at the end so that works quite well now the next problem is the player is not facing the right direction when they're moving so in order for the player to face the right direction I'm going to create another variable definition I'm going to create a variable called facing I'm going to set it to one now facing will indicate which way the player is facing one is facing to the right - one is facing to the left and we can use this if variable check to ask questions let's drag it in down the bottom and how it works is we say if a variable is equal to or not equal to a value then we can do something and the if it is true appears on this side if it is false it'll go down here so if that variable of HSP is firstly not equal to zero want to make sure when HSP value is not zero then we'll drag another check over and we'll say if the variable is actually greater then zero that means we're moving to the right so let's assign our facing variable the value of one now if that's not true if our HSB is not equal to zero it's not greater than zero then that means it's actually less than zero so we can drag an else over and we'll put it down the bottom here so our else is saying if this is not true then we'll do this and what we want to do is drag it to the little section on the right and we want to assign our facing to be minus one so now facing variable indicates which way our player is placing so now we want to use that variable to change which way the sprite faces so let's go and add a drawer event now a drawer event happens every step of the game and it's what is used to draw the player if we don't do anything here in the drawer event the player is drawn automatically but as soon as you create a drawing in and do something the player is no longer drawn and you have to do it manually yourself so if we go down here we can do it manually and we're looking for now draw a sprite transformed so let's drag that over because we want to do this because we want to use our facing variable for the image X scale which is the orientation of the sprite which way it's facing so what I want to draw is the sprite of the current player and the sprite of the current player has a variable name it's called sprite underscore index I'm going to use that now the frame is what frame we are currently showing now I don't wanna get too complicated and too technical with the first lecture so I'm going to use our image index which is the frame that is being shown for the player now our X&Y I'm going to take relative because I want to change them to zero and zero I want to add zero and zero to them so I just want to use the existing X&Y I can tick this and that will stay the same you can also uncheck this and just write x and y and with that UNTAC the same it'll mean the same thing but I'm going to keep it consistent and just make it easy to do that because in the future it's easy to tick those and type anything else in now this is the one we're here for the scale x and the scale y till show which way the sprite is scaling now I want to put the variable facing into the scale X section we will leave Y is 1 and everything else I'm going to leave the same so let's test that now so now when we move our sprite flips around the correct way because they're facing variable is used to change that now that's all for our intro tutorial on building a platformer using drag and drop in the next one I'll show you how to do collisions in the meantime if you're interested in making games I have two courses over at udemy one is a beginner course and the other one is more a beginner intermediate course and I'll show you how to make a tile based platform or using game maker I'm putting a coupon code for ninety percent off my course down in the description so go over there and have a look there's an intro video that you might be interested in but for now I look forward to seeing you in the next tutorial where we do the collisions thanks for joining me ceiling [Music]
Info
Channel: Slyddar
Views: 121,076
Rating: undefined out of 5
Keywords: gamemaker, platform, platformer, drag, drop, dnd, dragndrop, drag n drop, tutorial, peter morgan, one way, oneway, fall, make games, shaun spalding, heartbeast, spalding, yoyo, gms2, gms, advanced, learn, drag and drop, collision, make game, jump on head, enemy ai, horizontal, collisions, Gamemaker Studio 2, studio
Id: HJObUVyhLaQ
Channel Id: undefined
Length: 14min 0sec (840 seconds)
Published: Thu Apr 04 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.