GML Blog‎ > ‎Fundamentals‎ > ‎

Your First GM Game

Your ready to make your first game in Game Maker using GML. Let's begin by firing up the old GM program. Once Game Maker is open, click file -> [new]. We have now started a new game. Just to be safe, lets save the blank game as MyFirstGame.gmk. This can be done by going to file -> [save]. Our game needs a couple pieces to make it work. It needs objects, a sprite, and a room. Let's start out easy and make a sprite and a room. The easiest will be the room. A room is nothing but a level in your game. You can have as many rooms as you like but for starters, lets just make one. On your left hand side you will see a bunch of resource folders. These folders will house all of the pieces that will make up your game. Towards the bottom of the list, you should see a rooms folder. Right click that folder and select [Create Room]. You can leave that window open for now. We will need it later.

To make a sprite, right click the sprites folder and click [Create Sprite]. Another window opens up. This is the sprite properties window, there are many things you can set here but for now lets just make a simple sprite. Click on edit sprite. The window that just opened up will have all the images of that sprite. We haven't created any yet so lets do so by clicking file -> [new]. The horizontal and vertical size of the image will be 32 pixels by 32 pixels. This is fine. Click [Ok]. Now there is a blank sprite in the window. Double click it. You can spend some time in this window and experiment with the different buttons and such. Once you have made a rather large shape, press the [Checkmark] at the upper left of this window. Press the next [Checkmark] that appears in the upper left. You should now see the sprite properties window again. Change the name (upper left) to spr_thingy. When you get more comfortable using Game Maker, you can check out the Naming Conventions article to find out why I want you to name your sprites and such in this manner. After you have renamed the sprite, uncheck the precise collision checking check box. Were only doing this because it will make it easier to play the game. Any time you feel like learning more about Game Maker, press the question mark at the top right hand side of the program. This is the documentation for GM. You will find almost everything GM related in that help file. Now click [Ok] in the bottom left of the sprite properties window. We have the sprite (image), and a room.

The sprite won't do anything by itself so lets add an object. Objects are what drive Game Maker, or any other object oriented language for that matter. They have variables and can interact with each other. Right click the objects folder and click [Create Object]. Name it obj_thingy. In order to see this object you have to attach a sprite to it. Select spr_thingy from the drop down menu that's right below the name entry box. Now, objects in game maker have something called events. Go ahead and click the [Add Event] button in the middle. Select [Create]. Now click the [control] tab at the right hand side of the Object Properties window. Click and drag the button that looks like a piece of paper (not the one with a green triangle) onto the blank white space to the left of the button. The code editor just popped up. Write this in the code editor:

speed = 3

direction = random(360)

What you just did was put a code action in the create event of obj_thingy. What this means is that every time that obj_thingy is created, it will execute whatever code you wrote down. Anything can happen to an object though so lets add another event. Click [Add Event] again but this time choose the Other -> Outside room option. Put another code action in that event. This is the code you should write:

x = room_width / 2

y = room_height / 2

room_width and height are predefined variables for Game Maker. Whatever the rooms width or height will be, when obj_thingy is outside of it, it will go right to the center because any length divided by two gives you the center. Were almost there. We have to be able to click these obj_thingy's. Add another event. This time make it mouse -> Left pressed. Make sure it's not Left button or you will be able to cheat. Put this code in that event:

instance_destroy()

The last thing you have to do is finish making the room. Close any windows except for the room of course and click the drop down menu underneath where it says "Objects to add with left mouse:". Select obj_thingy. Now click inside the room (The grid to the right). You just added an object to the room. Add a bunch more (Thirty if your feeling lucky) and you'll be ready to play your first game! Close any remaining windows and click the green triangle at the top left of Game Maker. To win at your game, click all of the remaining obj_thingy's! There is a whole lot more for you to learn but with the Game Maker help file and websites like this, you will be able to make almost any game you can think of.

Affiliates