Ben's Game Warehouse

Click here to edit subtitle

If you want to have the GMK for this tutorial, you can download it HERE.


This is a pretty long tutorial, and if you just want to see one thing, put these titles into find by hitting ctrl f


Basic Sprite Creation

Basic Objects

Comments and if Statements

Creating a Room and Playing the Game



Before we get started, we need to get some stuff out of the way first. After downloading and installing Game Maker 8.1 Lite, open it up and you should see this screen.

It looks pretty bare. Why don't we fix that by changing it from simple mode to advanced mode. Hover over file, and click advanced mode.

Now, it should look like this:

Great! Now we have everything and can get started. First I'll quickly explain what the important things on this screen are.

Sprites - Sprites are images. These images act as a mask to objects. They don't actually do anything, they just act as a visual as to what is happening in the game. They're pretty self explanatory, so I won't go over them into depth yet. I'll save another tutorial just for sprites and sprite animation.

Sounds - Exactly what they sound like. These can be sound effects, or background music. Game Maker does not have a built in sound editor, so you need to bring in your own sounds. The best place for getting your own free sounds is a program called SFXR by Dr. Peter.

Backgrounds - Backgrounds are images placed as backdrops to rooms. The background editor is almost exactly the same as the sprite editor. The only main difference is that backgrounds can be made into tile sets which I will get into another time.

Paths - Paths create custom and definite routes for objects to follow. I will not be covering these, as I don't find them very useful in the games I make.

Scripts - Scripts are a bit more advanced. They use GML (Game Maker Language) to create arguments. I won't be covering these either.

Fonts - Also exactly what they sound like. Fonts are used to modify text in draw events. These don't take much explaining, but I will go over them when I cover drawing.

Time Lines - More specific alarms. These create time lines in steps (game time) for doing scripted events in an object. These are good for creating complicated AI and other such things.

Objects - The most important part of making games. Objects are the brains of your game. They become visible by using sprites. Objects are your player, enemies, ground you step on, items you collect, and everything you can see that isn't in the background. Objects work by setting events to them which perform different actions which is written in DND (Drag n' Drop) or GML. I will not be covering Drag n' Drop programming as it is not a valid way of making complicated games.

Rooms - Where you play the game. This is wear you place your objects, set your backgrounds, and play your game. This is the fun part. I will go over creation code, views, and all of the other useful things that go along with rooms as well.

Now that we've gotten that out of the way, let's create a basic sprite.

Basic Sprite Creation

Let's create a new sprite by clicking on the red pacman icon at the top or right clicking on the sprite folder and clicking create sprite. You should then be at this screen below. Go ahead and rename the sprite to spr_player. There are a lot of different sprites, objects, background, and rooms that we'll be creating. We need to tell the difference between each type. So we put spr_ in front of our sprites.

Once that's done, hit edit sprite.

Now hit new sprite and change the dimensions to 16 X 16. Then, hit OK and double click your sprite to start drawing.

Now your screen should look like this.

Most of these buttons should be pretty familiar if you've used any kind of paint tool, so I won't go in depth. Click the circle tool, and create a circle. Then, use the paint bucket tool to fill it with color. Once you're done, hit the check mark/OK until you're back to the main screen.

Basic Objects

OK, now we're going to make a new object. Click the blue sphere at the top or right clicking on the sprite folder and clicking create object. Then rename your object to obj_player. Similar to sprites, we will add the obj_ at the start of every object to make sure the game knows the difference between player: the sprite and player: the object. To give an object a sprite, click where it says <no sprite> and select the sprite we just created, spr_player.

As you see here, there are two columns. One is for events and one is for actions.

Events - Declare when and how an action will occur.

Actions - Declare what an object does within an event.

Let's look at some of the events. I'll try to explain each one briefly, but we will only get to use a few in this tutorial.

Create - This event only takes effect when an object is first created in a room.

Destroy - This event only takes effect when an object is destroyed

Alarm - When you click this event, you are given the choice of Alarm 0, Alarm 1, Alarm 2... through Alarm 11. So you can have 12 alarms in total. This event only takes effect when the alarm goes off. An alarm has to be set in another event before it can go off.

Step - When you click this event, you are given the choice of step, begin step, and end step. A step event goes through its events once every step. A step is set in each room, defaulted at 30 steps per second. Begin step occurs at the start of a step while end step occurs at the end of a step.

Collision - When you click this event, you are shown all of the objects in your game. That's because a collision event occurs when this object collides with another.

Keyboard - When you click this event, you are given many choices for keys. This event occurs while you are holding the key that you specify.

Mouse - This event is the same as the keyboard event, but for the mouse. You are also given mouse pressed and mouse released options.

Other - Misc. events. Too many to cover here, most are self explanatory. 

Draw - This event is special. It is the same as the step event, but it only is used for drawing on the screen. This is used to create images on the screen that are not objects and can't be interacted with such as HUDs, text boxes, menus, pictures, etc.

Key Press - This event only occurs on the step when you first press a key.

Key Release - This event only occurs on the first step when a key is released.

Trigger - I honestly have no idea what this is. It's only for GM Standard and I've never used it. I won't be covering it.

Whew, now let's get to some coding! Add a step event, and click the control tab far right actions section and right click where it says execute code

Comments and if Statements 

Now you should be greeted with this:

It might seem overwhelming, but that's why I'm here. Let's make the player move. To do that, we need a function. We want to tell the game that when we press a key, the player moves in a direction. We'll start with the up key.

Before we get into coding, note that all code is case sensitive. Nothing should be written in capital letters unless you are commenting, creating/accessing variables, writing within " ", etc.

Let's take this apart piece by piece.

At line 1 I created a comment. Comments are not a part of the code. They are used to tell the coder what something is doing, and it keeps you organized. 

A comment is created by putting two forward slashes in front of your comment like this:

//Example comment

Or by placing a forward slash and an asterisk in front of your comment and ending it with an asterisk and a forward slash. This lets you continue your comment through your code until it hits the asterisk forward slash.



Below that is an if statement. And if statement works like this: 

If this is true {this happens}

So that means the code is saying this: 

If the right arrow key is pressed, move upward at 2 pixels per step.

keyboard_check() is a function. It's checking whether the key in the parenthesis is being checked. 

vk_up is the up key. vk stands for virtual keyboard. There are other virtual keys as well, such as vk_right, vk_space, vk_enter, etc.

vspeed=2 is within the brackets. vspeed is a variable that contains this objects vertical speed. hspeed is horizontal speed. The value -2 indicates that the object is moving upwards at 2 pixels per second.

A negative vspeed means you're going up. 

A positive vspeed means you're going down.

A negative hspeed means you're going left.

A positive hspeed means you're going right.

Now let's add the other movement functions.

Hopefully this makes sense to you now. But we're not done yet. What will happen when we let go of our keys? The player would continue to move because it wasn't told to stop. So let's add some keyboard_check_released() functions. It's mostly the same as the code above, but we need to set our vspeeds and hspeeds to 0.

Hopefully this is self explanatory. Now we have a player! But before we can test the game, we need to put our object into a room. So let's do that. Hit the check mark to close out of this code, and hit OK to leave the object editor. Now click on the window icon in the tool bar or right click on the room folder and hit create room.

Creating a Room and Playing the Game

You should see this screen. Go up to where it says Snap X and Snap Y and change it to 16 X 16. This is the grid alignment. You usually want to have your alignment the same as the dimensions of the object you're placing. Then, place the object in your room by left clicking.  

But before we close, go to the settings tab and change the speed from 30 steps per second to 60 steps per second. This will keep your game nice and smooth. 

Now we can test the game! Click the green arrow in the tool bar to run the game, assuming you're done everything as I have you should be able to move the character in all 8 directions and the player should stop when you release your keys.


That's all for this first tutorial. Assuming you understand if statements, you should now be able to learn some functions on your own by going into the game maker manual by clicking the question mark in the tool bar. try experimenting with functions such as instance_create(obj,x,y) or instance_destroy() or any other you can find. I will cover as many as I can, but I can't cover them all. If you want to know the syntax for a function, look at the bottom of the code window when your cursor is within the parenthesis. 

Don't forget that the GMK for the game is downloadable at the top. In the next tutorial, I'll be covering other variables and how to create and access your own variables. I hope this was helpful, and thanks for reading.