• 01/07/16 05:09 PM
    Sign in to follow this  

    Creating your first game with Game Maker: Studio

    General and Gameplay Programming

    thegamedev

    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



      Report Article
    Sign in to follow this  


    User Feedback

    Create an account or sign in to leave a review

    You need to be a member in order to leave a review

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now


    Brain

    Report ·

      

    Share this review


    Link to review
    Micha

    Report ·

      

    Share this review


    Link to review
    BHXSpecter

    Report ·

      

    Share this review


    Link to review
    jbadams

    Report ·

      

    Share this review


    Link to review