Easing Into Code
In this tutorial, we dive into GameMaker Studio 2 and learn the basics of creating a sprite, an object, and writing our first line of code.
This video serves as a practical introduction to GameMaker Studio, demonstrating key features while guiding new programmers through their first steps in game development.
Lesson 4 Transcript
So let’s go ahead and open up GameMaker Studio 2. And if you open it up like this, this should be what you’re seeing. It’ll have some images up here talking about the tutorials or free stuff you can get, and you’ll have all of these options over here.
The one we want is new, so click on new, and then you’re presented with drag and drop and GameMaker language. Now, GML is what we’re going to refer to that as, and that’s what we want to use.
Drag and drop is a visual-based programming, and it’s really, really great if you’re just starting out, but there are some limitations. There’s some stuff that you just cannot do with it, and it also takes a lot longer and you’ll also find a lot less support for it.
So as a new programmer, sometimes it’s tempting to use the drag and drop because it’s actually easier when beginning, but if you ever run into a problem using it, you won’t be able to find support because anybody who’s making games is probably going to be using GML itself.
And that’s what we’re going to start with. So go ahead and click on GameMaker language. Give it a name like First Code Press. Okay, and it will open up.
So I’m going to increase the size over here, and what we’re going to do is we’re going to make a Sprite and an object, and we’re going to go through exactly how to do that now. So over on the resources, you can right click and create Sprite.
You can also do that with the shortcut Alt S, or you can come up to resources and click on create Sprite. I’m never going to do this because it’s way out of the way and it’s much easier to just do it over here. So right click and create a Sprite, and you are presented with this window right here.
Now, let’s talk super quickly about naming conventions, because once you start coding and developing anything like a large project, you have to have good naming conventions.
I’m going to be using something called Camel Case, which looks like this. So if I type a word, let’s say this is going to be a Let Player Sprite. So if I typed player, then the next word, the first letter will be capitalized. So the S Sprite. So that’s what that would look like. Now, that’s what I am going to use.
A lot of people instead, use underscore and no caps. Some people will capitalize each one and other people will do things completely different. That’s okay.
Whatever you do, just do it consistently because if you are not consistent, you will have a very hard time remembering what things are named and how to access them, and you will have a lot of errors and frustration. So whatever you’re going to do, just be consistent.
You to follow what I’m doing. That way if you have any problems and you ask questions, I’ll be able to help you easier, but whatever’s comfortable for you or whatever you’ve done in the past, feel free to do that.
The last thing I want to talk about naming conventions inside of GameMaker Studio specifically is we have all of these kinds of resources here and we need to use a prefix for each one. It helps to know exactly which one we’re referring to because if we create a Sprite for the player and then we make an object for the player, we cannot name them the same thing.
Resources can’t have the same name. So the way we fix that is by adding a prefix. So I’m just going to say Ss p R for the prefix for Sprites. That’s what I’m going to name all of my sprites is s p r first, and then we can put in what it is.
So I’ll tape this S p r player and press enter. And you can see over here it has also changed. Okay?
Now there’s a lot inside of here that we can talk about, but for now I just want to show you how to create a Sprite.
This window right here, double click on it or now this opened up so you can see that there are tabs up here. So if you want to get back to where we were, you go to workspace.
Okay, so I’m going to close that really quick. You can double click on that to get it, or you can click on this button right here to edit Image. Both of them will take you to the exact same place. Okay?
Now inside of here, GameMaker Studio has a pretty robust Sprite creation tools, so you can make pretty much anything you want inside of here, including animated Sprites, which is really, really awesome.
We’re going to talk about animations later. For now, we’re just going to use a tool to create a circle.
So we have an ellipse tool, there’s an outline and a fill. So if we click on fill, you’ll see that it fills it up. If we click on outline, it will do an outline.
All right, let’s go ahead and do a filled one for now. Choose any color you want. I’m just going to start at the top, drag it all the way to the bottom, and then I’m going to choose another color, and this is the paintbrush tool over here at the top.
If we click on this, we can actually just draw regularly. If you want the brush to be a different size, you have some pre-selected sizes right here, or you can choose exactly what size you want with this right here, if you go really large, it’ll cover up the entire screen, which is not what you want.
So I’m just going to keep mine at one and I’m going to draw something like this. There’s a happy look and player. Now, I am not an artist, so whenever I do some custom art, it’s going to be very bad and very silly. If you are an artist, I encourage you to take the time,
Make something a little more complex, but don’t spend forever on it. We want to get to the next part, which is when we actually do a little bit of coding. So we have a player, let’s close this and you can see he’s right here now.
Now let’s go over to objects. We’re going to right-click and create an object, and the prefix for objects is going to be O B J, and I’m just going to name it player. So now we have a Sprite player and an object player. So now we can do a lot of stuff over here.
For now, all I want to focus on is assigning the Sprite. So you click on no Sprite, and then you can choose the one we made. You can choose no Sprite. You can also choose to create a new Sprite from right here in this object if you wanted to and have it automatically assigned to it.
That can be really helpful.
If we choose the player, we can edit the Sprite and we can also edit the images directly. If we click on this, it opens that back up, which we’ve seen before. And if we click on this, it’ll take us to this window of the Sprite where we have all the options to edit inside of there.
Now, that’s our Sprite, and this is our object. Now I want to show you how to program inside of GameMaker Studio, and then we’re going to do a more in-depth discussion of it in the next video. GameMaker Studio is event driven, which means that if you go to ad event, you have all of these options, things that can happen to the player, and that’s where you put in the code.
What I want to do right now is add a step, event step, and then we come over here.
If you double-click on this from wherever you are, it will focus it getting around Game Maker Studio. If you hold space and then click and drag anywhere, it’ll move it around, which is really, really helpful. So I’m going to double-click on that.
I’m not going to worry about this first line. Instead, all I want to do is type Y equals Y plus five, and you can see there’s a little star here, which just means that we’ve made changes that have not been saved. You can press Ctrl Ss to make it go away, or if we bring it back by pressing space, we can just press F five or click run up here.
That will save your game, and then it will run it. So if we do that, oh wait, nothing happened. Okay, that’s because we forgot to actually put our object in our room. So let’s double-click on our room. It will open it up in a new window.
And again, there’s a lot of stuff here which we’re going to cover, but not right now. Instead, make sure that you have this instances layer selected and you click on the player and you drag it in
Here. Just put it right up near the top. If you click on the background and you try to drag it in here, you’ll get a red error and it will not work. So make sure you have instances selected and you put it right there.
Let’s click run again, and now we’re going to see our player move down the screen and disappear off of it forever and ever. Okay, that is your first Sprite, your first object, and your first line of code.
Congratulations. That’s awesome.
So what we’re going to cover next is what we just did and how it worked, because you’ve got your first line of code here, you added an event, but what does that mean and what do you do with it? That’s what we’re going to talk about in the next video.