Creating your first game with Game Maker: Studio

Published January 07, 2016 by Gurpreet Singh MAtharoo, posted by thegamedev
Do you see issues with this article? Let us know.
Advertisement

Introduction

So you want to start creating your own games? Then you've come at the right place. This article will get you started on creating simple 2D games. Note: After you've read this article, I suggest you go for this course: https://www.udemy.com/gamedeveloper/?couponCode=ONLYforGAMEDEV Following this link you can buy my Game Maker: Studio course for just $12 (52% off) and learn making 2 games in just 2 hours.

Game Maker: Studio

What is that?

Game Maker: Studio is a popular game development software used by many Indie Game Developers all over the world. It's easy; yet powerful. It has a free version which is capable of making good games for Windows. Further, the professional version can be bought for more features and can be extended by buying packages to be able to make games for different platforms such as Android, Mac, iOS, etc. There are mainly two ways of creating your game: Using the Drag&Drop actions, or by coding. In this article, we'll make our game using the coding language of Game Maker: Studio, which is called Game Maker Language and often abbreviated as GML. Don't worry, it's very easy. Let's proceed.

Understanding the basics

Before starting, understanding the basics is a must. Let's see how a game is created in GM:S.

Sprites

Sprites are the images created/imported in the software to be used for different things such as the character, a block, the wall, or the boss. A sprite can be a single image or a series of images (or sub-images) which results in an animated sprite. Sprites can be created using the sprite-editor in GM:S or can be imported from any file.

Objects

Objects signify different elements of a game, such as a character, a block, a power-up, an enemy, or anything. So every different element, or simply object of a game needs a different object. Sprites can be assigned to objects. Further, you can add events, actions and code in the object which define its actions, and then can be placed in a room, which will be shown when you play your game. Note: If you understand this completely, then, good for you. If not, or if you're confused, don't worry - just keep reading. You'll get it eventually.

Rooms

Rooms can be defined as levels in your game. A room is a rectangular space - its size is defined by its width and height in number of pixels. (Example: A width of 1024 and a height of 768 pixels will result in a room of size 1024x768) After a room is created, objects can be put in the space of the room, and a level can be designed in this way. This way, many rooms, or levels, can be created. When you start your game, the first room is shown first.

Our first game!

So now that we're done with the basics, we'll start by creating a simple game. We'll be making a simple character who needs to collect coins to win, avoiding the enemies. Start Game Maker: Studio. You'll see a small window with many tabs. Open the New Tab, enter your project name and click on Create. You'll see an empty window with many folders in the left pane. That's where all of the Sprites, Objects, Rooms, Sounds and everything is sorted. Quite neat, isn't it? ;)

Sprites

In that left pane, the first folder will be Sprites. Right-click on it and select Create Sprite. You'll see sprite0 under the folder Sprites - that's your first sprite! A small window will open - that's the sprite manager. It shows your sprite with many options. It's empty for now, because you haven't created or imported any sprite. Name it spr_player, because it will be our player's sprite. Click on Load Sprite to load any image file for the player, or click on Edit Sprite to create your own.

Creating your sprite

Now that you've clicked on Edit Sprite, another window will open: This is where all of the subimages of your sprite are created. From the menus on the top, open the File menu and select New.... Enter the dimensions of the sprite in the window that opens. In our case, we'll use width: 32, height: 32. Hit enter, and in that window, a small sprite will be created, with the name image 0. Wow. You just created the first subimage of your sprite! Double-click on the sub-image you just created. Another window will open, and this one is the sprite editor. You'll see it's mostly like Paint. Now - use your creativity! Create your player, as you like. Remember: We're creating a Top-Down game, which means the player must be created as seen from the top. And, it must face right: or else it'll cause problems. Now, create! :D ... Done with the sprite? Click on the Green Tick on the top-left in the window. It'll close, and in the sub-image editor you'll see your player image. Again, click on the Green Tick. There's your sprite! Under 'Origin', click on 'center'. This is the point from where the sprite will rotate; and it must be the center. Now click OK to save the sprite. Now, in the same way, create these sprites: a wall block, a coin, and an enemy - and remember, they too must be from the top and the enemy also should be facing right. Don't forget to name them after "spr_"(Like spr_player, spr_coin). Use the size 32x32 for all of these sprites.

Objects

Done with creating the sprites? Let's move on to creating our objects. Find the objects folder from the left pane, right-click on it and choose Create Object. Your object (object0) will be created and the object manager window will open. First of all, change the name from object0 to obj_player. Yes, obj_ will be used as the object name prefix. Prefixes: Name prefixes such as spr_ (for sprite names), obj_ (for object names), room_ (for room names) aren't compulsory but they're used so that it's easier to reference them in code. For example: A coin is a coin but while coding, you'll know what you want to reference and it will be easier: spr_coin for the sprite and obj_coin for the object. Now, under the place where you typed the name of the object will be a menu where you can select the sprite you want to use with the object. Click on it and select spr_player. Click on OK to save the object. Now, in the same way, create objects for the coin, the wall block and the enemy. Wow! Do you realise that you're creating your own game? You're not far away from getting it running. Just keep reading! Done with creating the objects, and assigning sprites to them? Good. Now let's start the next step.

Coding

Double-click on obj_player. In object manager, you'll see two empty panes: the one on the left is the event pane, and the one on the left is the action pane. Events are the specific events which trigger the actions inside them. For example, actions inside the 'left arrow key' event will be executed when the left arrow key on the keyboard is pressed. The 'Create' event works when the object is created first, and that's the only time the actions inside the create event are executed. Actions inside the 'Step' event will be executed every step: or every frame. By default, there are 30 steps in a game, so it means actions inside the Step event will be executed 30 times a second. Woah! Similarly, there are many events. Room Speed, which tells how many steps there will be in the room, can be changed from the room settings. Default is 30. Now, right-click in the event pane and select "Add" or just click on "Add Event" below the pane. A small window will open, which contains all of the existing events. Click on Keyboard, and select Left Arrow Key. Similarly, add events for Right Arrow Key, Up Arrow Key and Down Arrow Key. Now we'll add the code for these events. Click on the Left Arrow Key Event. Now look at the action pane - in the rightmost pane, there are many events which can be dragged into the action pane. They're called Drag & Drop actions. We'll not use them; we'll use an action which is used to add code. See the many tabs on the right side? Open the control tab. From the actions there, choose the first action under the name "Code". (There will be total 3 actions under 'Code') Drag it into the action pane. A window will open - it's the text editor for entering the code. Enter this code in the window: x-=3 Let me explain what this does. x is the horizontal property, so it defines the horizontal position of the object in the room in the number of pixels. Similarly, y is the vertical property - it defines the vertical position of the object. So, x=254 will change the horizontal position of the object to 254 pixels in the room. If x increases, the object will move right. If it decreases, it'll go left. If y increases, the object will go down, and if it decreases, it'll move up. What we're doing is telling the object to move left when Left Arrow Key is pressed - so we're decreasing its x property, by using x-=3 - which means subtract 3 from x. Now click on the Green Tick at the Top-Left. You'll see that your code action has been added in the action pane. You can open and edit the code any time just by double-clicking on the action. Now, in the same way, add codes for the other Arrow Key actions. Open the next event. Drag the Code action from the control tab of D&D (Drag and Drop) menu. Here are the codes for the arrow keys: (I suggest you first yourself guess what the code will be based on what I told you in the previous paragraph about reducing and increasing x and y to move) Right Arrow Key: x+=3 Up Arrow Key: y-=3 Down Arrow Key: y+=3 Added the code? Press OK to save your object. Let's move on to creating the room.

Rooms

Find the Rooms folder in the left pane and... I think you know what to do. Right Click > Create Room. Your room, namely room0, will be created. We'll let this be the name. Another window opens - this one will be the room manager. You'll see an empty space along with a left pane and some options on the top - that empty space is your room, basically what you'll see when you start your game. In the left pane, there will be many tabs. Open the Settings tab, and change the room width and height to 800 and 600, respectively. Now, open the Objects tab. Before adding objects, change both x snap and y snap to 32, which are found on the top in the room manager window. Now, in the left pane, click on the empty pane under the tabs. A menu will open with all of your objects. Click on the wall object (obj_wall). You'll see its sprite there - it means that the object has been selected. Now, use your mouse to add the wall blocks in the room (that empty space on the right). Left-click to add one or hold Ctrl+Shift while Left-clicking to continuously add them. What you want to do here is create your level - design it. Add the wall blocks so that the player has to navigate through the level to find the coins. If you misplace any object, they can just be dragged and re-placed, or deleted using Right Click > Delete. Done with adding the wall blocks? Now select the coin object (obj_coin) from the left pane and add 10 coins in your level. After adding the coins, add a few enemies. Add them at a place where they can move up - where a wall block is not blocking their way. After adding the enemies, select obj_player and add it into the room. That's where our player will start, so choose a nice place. Now save the room using the same green tick you see in every window. Now let's add more code. We've just made the player move. Double-click open obj_coin. Click on Add Event and choose Collision and select obj_player. This is the event that triggers when the object (obj_coin) collides with the object you just selected (obj_player). Let's add code in it. Select the event, open the control tab, and drag the Code action into the Action Pane. Add this code: score+=1 instance_destroy() score+=1 will increase the score by one everytime the player gets the coin. instance_destroy() will delete the object instance of the coin. That's to show that the player had taken the coin. Click on the Green Tick. Press OK to save the object. Now, open obj_player. Add a collision event with obj_wall. Add Event > Collision > obj_wall Add this code in it: x=xprevious y=yprevious This code restricts the player from walking through the wall block. xprevious is the previous x property of the object. yprevious is the previous y property of the object. When the player collides with the wall, its position is immediately changed to its previous position (before the collision), stopping it there. Click on the green tick. Add another collision event, this one with obj_enemy. Add this code: room_restart() This will restart the room whenever the player collides with the enemy. Click on the green tick. Add Step event. It executes 30 times a second. In its code, add: if x>xprevious image_angle=0 if xyprevious image_angle=270 if y This code rotates the player based on where it's going. Copy this code because we'll need it again. Click on OK. Now.. It's time to open obj_enemy. Add create event. In its code, add: vspeed=-1 This code will set its vertical speed to -1, which means it'll go up. Now add step event, and add the code I told you to copy.(the code of obj_player's step event). Now add a collision event with obj_wall and add this code: direction-=180 It'll reverse its direction and the object (enemy) will move down instead of up. Now if a collision happens again, it'll go up. Click on OK to save the object.

Now let's test the game!

Press F5 to start the game. Test it. Move your player using the Arrow Keys. Collect the coins. Run into enemies. Isn't it cool? Your own game! Now close the game window. Let's make winning possible. Open obj_player and in the Step event, add this code. if score=10 room_goto_next() This one is simple: it checks if the score is 10, and then opens the next room. This is how it works: after if, comes the condition (score=10, here) and then the action which must be performed if the condition (score=10) is true. Now green tick, OK. Now, create a new sprite. Name it spr_play. Click on Edit Sprite. Open File menu, select New. Enter the size as width = 600, height = 400 and press OK. Double-click on the sub-image that is created. From the left pane, use the Text tool to write this there: "You Win!" or "You completed the game!" or whatever you like - it's your game. There's an option to change the font and size in the left pane, and to change the color in the right pane. Click in the empty area to add the text. After adding it, add another text: "Click here to play again" The text must be big enough for the player to click on it. Now save the sprite. Create an object for it, namely obj_play. Click on Add Event. There'll be a Mouse event. Click on it, and select Left Button. Open the event and add this code: room_goto(room0) This will take the user to the first room (room0) when they click on the sprite so that they can play the game again. So let's create a room for it! Right-click on the Rooms folder and select Create Room. When the Room Manager for the new room opens, open the settings tab and rename it room_play and change its size to 800 and 600 (like the previous room). Add obj_play in the room, wherever you like.

Testing time!

Press F5. Play the game, collect all of the 10 coins and win. It'll take you to the next room (room_play), and when you click on the text, it'll take you back to your game. Fun, isn't it?

Adding more levels

You can create as many levels as you want. Just do this: Create a new room, change its size (800,600), add the wall blocks, coins, enemies, and the player, as you did in the first room, but differently: because this is a new level. Make sure the snap x and snap y are 32. After clicking on the green tick, take a look at the Rooms folder in the left pane. It'll be like this: room0 room_play room2 This means that you can't access room2, because it comes after room_play. So, what you need to do here is drag room2 where room_play is, so that after the first level, the next level comes, and in the end, room_play. This way, you can create as many levels as you want. Press Ctrl+S to save your project.

Creating an executable

Open the File Menu, and select Create Executable. A window will open. Select the folder where you want to save your game as an *.exe. Enter the name at the text field at the bottom. Select Executable from the drop-down list below it, and hit enter. You can now share the exe file you just created to share your game!

Conclusion

So creating a game wasn't that hard after all? Game Maker: Studio really does a great job at helping you create your game. There are many things to learn about this great software - so never stop learning! If you found this article helpful, please consider sharing it so that it can help other people also. Have some suggestions, need help or did I make a mistake? Comment below or mail me at gurpreetsingh793@gmail.com. Have a great day!

Article Update Log

10 Jan 2016: Sprite origin explained 16 Dec 2015: Updated about the price. 12 Dec 2015: Initial release

Cancel Save
0 Likes 17 Comments

Comments

jbadams

I think this articular article could use some clean-up.

Firstly, there are stray h2 closing tags scattered throughout the article that should either be removed or preferably paired with opening tags to achieve the desired formatting.

Secondly, the introduction proudly states that Game Maker: Studio is free, which I would consider to be misleading. There is a free version of the software which is still quite capable, but that version has a few limitations and is notably unable to deploy to the majority of target platforms supported by the software; the full package with all exporters is not particularly cheap.

Beyond that I haven't looked over the actual content of the article for correctness, but at a quick glance, assuming the information is correct it looks like it may be a passable walk-through of how to create a very simple game with the software.

December 16, 2015 04:43 AM
thegamedev

I think this articular article could use some clean-up.

Firstly, there are stray h2 closing tags scattered throughout the article that should either be removed or preferably paired with opening tags to achieve the desired formatting.

Secondly, the introduction proudly states that Game Maker: Studio is free, which I would consider to be misleading. There is a free version of the software which is still quite capable, but that version has a few limitations and is notably unable to deploy to the majority of target platforms supported by the software; the full package with all exporters is not particularly cheap.

Beyond that I haven't looked over the actual content of the article for correctness, but at a quick glance, assuming the information is correct it looks like it may be a passable walk-through of how to create a very simple game with the software.


Well, thanks for the helpful comment! I've updated about the price thing but about the <h> tags, I think that's a problem. I used to use those tags but the opening tag would just disappear after saving, resulting in stray closing tags. I used bolding(<b>), as I did now. I think the admins here changed those boldings to headings using h tags but you see, the problem about the opening tags disappearing. :-)
December 16, 2015 05:35 AM
Eck

Looks like I didn't save my comment when I voted it down. Essentially it was what jbadams said. :) You still have a couple of dangling closing h2 tags.

December 17, 2015 12:25 AM
Gaiiden

Well, I put in the time to get it cleaned up but it's back to just regular bold headings. I'm not sure how that happened because when I last looked at it when it was published it looked fine.

If you are using <p></p> anywhere take them out. You don't need them and they will cause the rest of the tags to break

December 17, 2015 02:05 AM
thegamedev

Well, I put in the time to get it cleaned up but it's back to just regular bold headings. I'm not sure how that happened because when I last looked at it when it was published it looked fine.

If you are using anywhere take them out. You don't need them and they will cause the rest of the tags to break


I changed them to (b) tags because the opening (h) tags disappear.
Well, I changed them to (h) tags now, and, removed the (p) tags but they just appear again, and the (h) tags get messed up. :(
December 17, 2015 03:36 AM
thegamedev
I've edited the article about the h1 tags and they appear fine now. But I don't know when they'll get messed up again. :-)
December 17, 2015 03:58 AM
Gaiiden

yea when I click to edit I see <p> right at the start - so you're saying you aren't putting them there yourself? Are you taking the text out of the editor to use your own and pasting it back in?

December 18, 2015 02:40 AM
thegamedev

yea when I click to edit I see <p> right at the start - so you're saying you aren't putting them there yourself? Are you taking the text out of the editor to use your own and pasting it back in?


No, I'm not putting the (p) there. Not copy/pasting the text either. When I go to edit the article, the (p) appear for me too. :-)
December 18, 2015 04:14 PM
WoopsASword

A nice article,

I suggest adding images since beginners would probably seek help with the program.

December 18, 2015 04:38 PM
thegamedev

A nice article,
I suggest adding images since beginners would probably seek help with the program.

A nice article,
I suggest adding images since beginners would probably seek help with the program.

You're right, and I know that's important but my computer is dead so I'll have to wait until I buy the needed parts and get it working again. I wrote this tutorial from my phone.
December 18, 2015 05:36 PM
Dave Hunt

I wrote this tutorial from my phone.

That might explain the formatting problems you had.

December 19, 2015 12:49 AM
thegamedev

I wrote this tutorial from my phone.

That might explain the formatting problems you had.

I wrote this tutorial from my phone.

That might explain the formatting problems you had.

That was something with the website, which happened even when some admin here also tried to edit the article.
December 19, 2015 03:37 AM
Ovicior

Oh damn, this was lengthy... Can't believe you wrote it from your phone.

Welcome to the forum :D

December 22, 2015 04:01 AM
thegamedev

Oh damn, this was lengthy... Can't believe you wrote it from your phone.
Welcome to the forum biggrin.png


Oh damn, this was lengthy... Can't believe you wrote it from your phone.
Welcome to the forum biggrin.png


Oh haha! Thanks. :-) It took me almost 3-4 hours. Or maybe 5.
December 22, 2015 11:58 AM
dakotahlamb

Oh damn, this was lengthy... Can't believe you wrote it from your phone.
Welcome to the forum biggrin.png


Oh damn, this was lengthy... Can't believe you wrote it from your phone.
Welcome to the forum biggrin.png


Oh haha! Thanks. :-) It took me almost 3-4 hours. Or maybe 5.

Thanks for the effort!

January 05, 2016 05:58 PM
thegamedev

Oh damn, this was lengthy... Can't believe you wrote it from your phone.
Welcome to the forum biggrin.png

Oh damn, this was lengthy... Can't believe you wrote it from your phone.
Welcome to the forum biggrin.png

Oh haha! Thanks. :-) It took me almost 3-4 hours. Or maybe 5.
Thanks for the effort!

Oh damn, this was lengthy... Can't believe you wrote it from your phone.
Welcome to the forum biggrin.png

Oh damn, this was lengthy... Can't believe you wrote it from your phone.
Welcome to the forum biggrin.png

Oh haha! Thanks. :-) It took me almost 3-4 hours. Or maybe 5.
Thanks for the effort!

Haha you're welcome. :-)
January 07, 2016 04:10 PM
thegamedev

Course coupon link updated. Was dead from months.

July 02, 2016 12:18 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!

So you want to make your own games? Then you've come at the right place! This article will help you create your first 2D game.

Advertisement

Other Tutorials by thegamedev

thegamedev has not posted any other tutorials. Encourage them to write more!
Advertisement