Make a Platformer in 13 Minutes in GameMaker Studio 2

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

He king's here, back at it again with amazing content!

👍︎︎ 3 👤︎︎ u/J6-4B 📅︎︎ Oct 09 2020 🗫︎ replies

Really good video but would have been better if he showed how to move from 1 level to another and added a point system.

👍︎︎ 1 👤︎︎ u/N1Wukong 📅︎︎ Oct 09 2020 🗫︎ replies
Captions
all of the assets and the code will be in the description [Music] to first open up a new game maker project go to file preferences sprite editor make sure the default sprite origin is set to middle center and the default sprite animation speed is set to 15. click on apply then ok now we're going to import all of the assets so drag and drop all of the assets of the game into the sprites folder then click on save and click on the idle animation for the player we are going to set the frames per second to 9 and we are going to change the collision mask so click on collision mask change the mode to manual and reduce the size of the collision mask of the player a little bit next we are going to create a tileset so right click on the tilesets folder click on create and select tilesets name it t-ground for tileset ground then we are going to assign the sprite of the tile set to this object so click on s tile set and by default the size of the grid will be 16 by 16 we are going to change it to 32 by 32 and we are going to use the auto tiling feature so click on auto tiling and add a new 47 tiles template now we are going to assign each style to the template so first click on the tile on the bottom right of the tile set and next we just have to click on every tile one by one to assign them to the correct position doing this will allow us to draw directly within the room editor with our tile sets without having to manually choose which style to draw so now we are going to go in the room editor so click on the rooms folder and click on room 1 and here first we are going to assign the background so click on the background layer click on no sprite select the s background sprite and we are going to change the size of the room to be the same as our background so change it to 960 by 540 and we're going to add the camera so open the viewports and camera toggle click on enable viewport click on viewport 0 and set it to visible we're going to set the camera width to 640 and the height to 360 which is the resolution of our game and we're going to set the viewport to be double that so 1280 by 720 which will be the size of our window next we can close this and now we are going to add our tile sets into the room so add the new tileset layer which is the third button and rename it ground next we need to assign our tile set to this layer so select the t-ground tileset and we are going to create a level thanks to the auto tiling feature so click on the libraries button and select auto tile 1 and now we can draw in the room with our tiles we can also control the size of our brush thanks to this button so now i'm going to draw a simple level and now we're going to create our player object so go back to the assets tab right click on the objects folder click on create object and name it or player next we're going to assign the idle sprite to our object and we're going to change the collision mask from same as bright to be the idle sprites so that the collision mask doesn't change when we change the sprite of the player now we're going to add the create event we're going to set up some variables we'll use one variable to set the movement speed of the player and then we'll have two more variables to apply that movement when the player presses the move buttons so the x speed variable will control the movement on the horizontal axis and the wide speed variable will control the movement on the vertical axis next we're going to add a step event and we're going to start by setting up three local variables the first local variable is x direction which will return 1 if the player wants to go to the right or minus 1 if he wants to go to the left and 0 if he doesn't move next we set a variable to check if the player is pressing the space button which is the key we use to jump and finally we're setting a third variable that will tell us whether the player is standing on the ground or not to do that we're going to use a function called place meeting which returns whether two objects are colliding or not at the given position so we are giving it the current position of the player and we adding one to the vertical axis to check the pixel just below the feet of the player and we're going to check if it collides with the overwhelm object this is the object we will create to manage the collisions of the game so let's create it right now so open up the asset browser right click on the objects folder create object name it orwall and we're going to assign it a simple sprite so right click on the sprites folder create sprite click on resize sprite and make it 32 by 32 which is the same size as our tile set click on apply then click on edit image pick a random color and pick the fill tool and then just fill the entire right with this color then we're going to adjust the opacity a little bit to make it transparent so double click on the default layer and reduce the opacity we're also going to rename it to s wall and we can close this window and we also need to set the origin to top left go back to the room window and we're going to create a new layer that contains the wall objects so create a new instance layer and name it walls so now we're going to draw over our tiles with wall objects so hold the alt button and place them where you want in the room and we can resize them by just dragging the sides of the box like this with that method you don't need to cover inside of the world where the player will never be able to go so now that it's done we're going to hide this layer so click on the little i on the walls layer and go back to the all player step event so next we'll add the line of code that changes the direction of the sprite of the player depending on the actual direction he's moving in so to do that we set the image x scale of the player to be 1 or -1 depending on the direction and we're going to modify the x-speed and y-speed variables depending on the direction the player is moving to so we set the x speed variable to be the x direction so 1 minus 1 multiplied by the speed so if the player wants to go right it will move by 4 pixels in the right direction and we are going to increment the y speed variable every step by one this will make the player be pulled down by gravity and next we're going to apply those speeds to the x and y position of the player we also want to check if the player is jumping and if that's the case we're going to replace the y speed of the player to be -15 since to go up we need to lower the y value so the lower this number will be the higher the player will jump so if the player presses the space button his y speed will go to -15 and every step after that it will go up by one so he will get slowly pulled down by gravity again we can test it so go back to the room go to the instances layer and place a player object and then launch the game now we can see that our player is being pulled down by gravity it goes through walls because we haven't implemented the collision yet and when we press the space button it jumps before being pulled down again so we've basically recreated flappy bird so now we're going to add the collisions so go back to the step event and first of all we are going to update the sprite of the player depending on what he's doing because right now he's only being in the idle animation so we're going to add this code before the jump check if the player's x direction is different than zero so if the player is moving to the right or to the left we're going to change his sprite to be the running animation and else we're going to set it to the idle animation but we only want to do that if the player is on the ground so we're just going to put all of this inside of a condition that checks whether the player is on the ground or not this way if the player is not on the ground he won't be able to jump and we are going to set his sprite to be the jumping animation this way anytime he's in the air he will be in the jumping animation and finally we need to add the code to check the collision with the wall object and to stop the player if he's colliding with one so we can add this code before changing the position of the player so we're checking if the position the player wants to move into in the horizontal axis is colliding with a wall or not if it's colliding with a wall we're going to set its speed to zero on the horizontal axis we're going to do the same on the vertical axis so we just copy this code and put it before changing the position on the y axis and we are going to remove this and put y speed instead and change x speed to y speed everywhere so let's try it so we can see that it works so now let's add some more control to the camera to be able to move inside of the whole room so create a new object and call it our camera place it inside of the room in the instances layer and in the create event we are going to set up two basic variables that will give us the width and the height of our camera and in the step event we are going to set the position of the camera to be centered on the position of the player so these two local variables will be the new position of the camera which is the position of the player minus half of the width and height of the camera since the origin point of the camera is in the top left corner so if you want it to be centered on the player we need to remove half of the size of the camera on both axis and next we're going to call a new function to set the position of the camera to the new position we calculate which is the camera set view pause function and we need to give it the camera we are using which is the view zero camera the one we set up in the room settings before and the new position so if we launch it now we can see that it works the camera is following the player but there are a few problems for example it goes out of the room if we are on the ground half of the screen will be black and it's useless so it needs to fix it so to do that we're going to use a new function which is the clump function we give it the same value as before but we tell it to not go below zero and to not go over the borders of the room this way x-cam and y-cam variables will still give us the centered position on the player but with some limits that will forbid it from going outside of the room so this is what it looks like now which is much better but we can also see that the camera is very snappy it doesn't feel very natural because it moves directly to the position of the player every frame so we can add some code to smooth it out and to do that we are going to use the lerp function so first we just retrieve the current position and we set up two new variables using the log function to which we give the current position of the camera and the position we want to go to and an amount of 0.1 which means instead of going directly to the position of the player the camera will move 10 percent of the way there every step so it will go faster when the distance is higher and slower when the distance is lower which will give it a smoother effect so replace x cam and y cam by the new x and new y variable and we now have a more fluid camera the last thing we'll do here is to add some parallaxing effect to the background to make it look like the background is more far away and we just need to add this code which will change the x and y position of the background layer to the new position of the camera multiplied by a number that's below 1. this means that instead of having the background be stuck in the same position during all of the game the background will also move to new positions depending on where the camera is which will give it the paralaxing effect and now when we move the camera we can see that the background also moves so the final thing we'll do here is to set the game to full screen and we can now create our coin object so create a new object call it allcoin assign the coin sprite to this object and we're going to place a few of them in the room and we're going to add a collision event in the all player object so click on new event collision object select the or coin object and in that event we're going to add this code which will play a sound and destroy the coin when we touch it you could also increase the score of the player or anything you want in this event also going to modify the collision mask of the coin so go to the coin sprite click on collision mask change the mod to manual and reduce the size of the collision mask and we're also going to add a new event on our player object that will allow us to test more easily so add a new event click on key pressed and select the letter r and we're just going to restart the game so now if we launch the game we can see that it works we can collect coins and if we press the r button it will restart the game now there's a small optimization that we can do that's not very apparent in this game because the numbers are so small but it's in the step event of the player object with this code in some situations the player will not be able to have a pixel perfect collision with the wall because we're only checking if x plus the speed which is 4 collides with the wall and if that's the case we just set the speed to zero but maybe x plus one would still not be colliding with the wall which there will be a gap between the player and the wall to fix that we just need to add a new loop instead of this condition that will add one or minus one depending on the direction of the player to the x position while there's still a gap between the player and the wall to check that we use the place meeting function but instead of giving it the x speed variable we just give it the sign of the x speed variable so it will be 1 or -1 depending on the direction of the player and as long as x plus 1 or minus 1 does not collide with the wall we're going to add 1 or minus 1 to the position of the player and we can do the same thing for the vertical axis and this should give us pixel perfect collision on both axes and that's all we need we now have the working platformer if you like this video feel free to subscribe and let me know in the comments if you want me to do the same for another type of game you
Info
Channel: Blobfish
Views: 33,383
Rating: undefined out of 5
Keywords: indie game, gamemaker, gamemaker tutorial, gamemaker studio 2, gamemaker studio, gms tutorial, gms, how to use gamemaker, how to make a platformer in gamemaker studio 2, how to make a platformer in gamemaker studio, gamemaker beginner tutorial, gamemaker studio 2 beginner tutorial, platformer tutorial gamemaker studio 2, gamemaker platformer tutorial, gamemaker platformer, gamemaker platformer movement
Id: uKXCI1qC_LQ
Channel Id: undefined
Length: 13min 17sec (797 seconds)
Published: Fri Oct 09 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.