Chapter 2
In This Chapter
Getting acquainted with the interface
Adding Sounds to your game
Making things pretty with Sprites
Bringing your game to life with Objects
Putting your Objects in Rooms
In this chapter, I provide a broad overview of some of the most used features and tools of GameMaker. That includes the interface, Sounds, Sprites, Objects, Actions, and Events. I go into much more detail on Actions and Events in the following chapters, but here I show you how to get started with creating and loading Sprites, adding music as a resource, and creating an Object that you can place in a Room. Buckle up, folks — this ride is about to start!
The basic work area within GameMaker consists of several sections. These sections are laid out in an organized manner to form the interface from which you work. You see a main menu along the top and an icon menu directly below that; these two menus provide separate ways of, say, creating a Sprite, loading a Sound, creating an Object, and so on. The icon menu is where you can find the Target drop-down list, which is where you tell GameMaker which platform you want to publish to, such as HTML5, Android, iOS, and so on (see Figure 2-1).
Along the left pane, you can find the Resource tree, which contains a quick list of resources, including Sprites, Sounds, Backgrounds, Objects, Rooms, and more. The bottom pane consists of a Compile window, which blasts into life when you run the game (meaning, when you run the game, you can watch GameMaker compile the game through a series of lines of text).
If you’re working from a tutorial, in the right pane you see the tutorial window. Figure 2-1 highlights the various parts of the interface.
When you create a new Object, or a Sprite, or a Room, or what have you, a new floating window appears. This floating window could contain several tabs of configurations, or it could have radio buttons, text fields, drop-down icons, drag-and-drop icons, and more. It’s within these floating windows where you do the majority of your work.
Sounds make up a large part of games these days. Everything from moody background music that builds as the player anticipates a challenging boss battle, to explosions, bullets firing, a character jumping (sproing!), and more.
To add a Sound resource to GameMaker, follow these steps:
The Sound Properties window opens.
You hear the Sound when you click Play and it continues to play until you click the Stop button.
You need to configure an external sound editor to work with GameMaker in order to edit a Sound. Read on for instructions on how to do this.
You can configure external editors to work within GameMaker. This includes sound editors, image editors, and code editors. To configure an external editor to work in GameMaker, follow these steps:
The Preferences window appears.
Your options are Code Editor, Image Editor, SWF Viewer, and Sound Editors (for WAV files or MP3 files).
A navigation window opens from which you can navigate to and select the editor you want on your PC.
A Sprite is an image, or a series of sub-images, that you assign to Objects. You can use Sprites to represent Objects in the game, such as the player (a ship or a character), explosions, walls, score displays, or anything you want in your game.
When a Sprite consists of a series of images, those images are known as sub-images, and they play continuously, as if they were mini-movies. That can give the appearance of a plane’s propellers rotating, an animated explosion, and so forth. Each sub-image within a Sprite is named consecutively (image 0, image 1, image 2, and so on), as shown in Figure 2-5.
The remainder of this section covers
To load a Sprite that already exists, follow these steps:
The Sprite Properties window appears (see Figure 2-7).
A navigation menu opens from which you can find an image on your computer.
To create a new Sprite from scratch, follow these steps:
The Sprite Properties window appears (refer to Figure 2-7).
The Sprite Editor window appears (see Figure 2-8).
The Create a New Sprite dialog box appears (see Figure 2-9).
A new Sprite, which consists solely of a transparent background at this point, appears in the Sprite Editor. You can now double-click this Sprite to open the image editor from which you can actually draw the Sprite.
To create a sub-image, you can choose one of the Create an Empty Image icons in the Sprite Editor (see Figure 2-10) to add the sub-image either before the current one or at the end. A new, blank sub-image appears in the Sprite Editor.
GameMaker has a built-in Image Editor (see Figure 2-11) that you can use to edit Sprites. To access the Image Editor, click Edit Sprite from the Sprite Properties window. Then double-click the image that you want to edit.
I don’t cover the Image Editor in this book, but the in-software manual goes into detail on it. Just press F1 in GameMaker to access the manual. Then choose the Index, search for “image editor,” and then choose Display at the bottom of the window.
When you have your Sprite looking the way you want it, you can configure the Sprite with different properties. This includes placing the Origin, setting the Collision Checking (which includes modifying the Mask), and using the Texture Settings. I go into detail on each of these configurations in the following sections.
The default anchor point, which is considered the Origin, is the top-left corner of a Sprite. GameMaker uses the Origin as a point of reference for rotating, scaling, and so on (for example, turning the image around when it bounces off a wall).
While in the Sprite Properties window, when you click Center (see Figure 2-12), you’re telling GameMaker to use the center of the Sprite as the anchor point (that is, the Origin). Chapter 6 provides a good example of working with the anchor point, in the section on creating the boss Sprite.
The Collision Checking settings are found in the middle of the Sprite Properties window (see Figure 2-13). Collision Checking refers to how the Object (an Object with the Sprite loaded) reacts when colliding with other Objects. You can select the Precise Collision Checking box (refer to Figure 2-13) for more accurate collision detection, but this could potentially slow down the game. You can also modify the Mask from the Sprite Properties window, as discussed next.
To set the Mask, follow these steps:
The Mask Properties window appears (see Figure 2-14).
If you select the Separate Collision Masks check box, you can set the Alpha Tolerance. The higher you set the tolerance, the more the partially transparent pixels are not affected by the Mask. Pixels become transparent as the Sprite transitions between sub-images. It’s during these transitions that the Alpha Tolerance comes into play.
By turning on Separate Collision Masks, you significantly increase the workload for GameMaker to run your game, which could cause performance issues.
If you select Automatic, GameMaker does its best job of forming a Mask around the Sprite; if you select Full Image, GameMaker selects the entire image, including the transparent background; and if you select Manual, you can configure the settings yourself by typing in values in the Left, Right, Top, and Bottom fields.
If you select Precise, GameMaker does its best to set the Mask exactly against the pixels. If you choose Rectangle, Ellipse, or Diamond, GameMaker creates a Mask based on the chosen shape.
When you select Precise, you significantly increase the workload for GameMaker to run your game (even more so than using a separate collision mask), which could cause performance issues.
In Chapter 8, you can find information on how to use fixtures instead of collision Masks, for when you want to make a physics-based game.
The Texture Settings, and in particular the Texture Group, can be useful when you start making very large games and you need to keep track of many different resources. Essentially, GameMaker enables you to save Sprites, Backgrounds, and Fonts to different groups for your reference later.
To create a Texture Group, follow these steps:
The Global Game Settings window opens.
A new Texture Group appears in the Texture Groups section.
The Rename Texture Page dialog box appears (see Figure 2-16).
The renamed Texture Page appears in the Texture Groups section.
Now that you have more than one Texture Group, when you’re in the Sprites Properties, you can assign that Sprite to the new Texture Group. From the Texture Group drop-down list, select the group you want (see Figure 2-17). Texture Groups do help optimize game performance.
In this section, I provide a quick overview of Objects, which are what make up the different parts of the game, such as the player, the enemy, the score display, and so on. Objects can also control the game through the different Events and Actions that you add to them.
To create an Object, follow these steps:
The Object Properties window appears (see Figure 2-19).
A list of available Sprites appears for you to choose from. Sprites provide a visual representation of the Object — you know, so that the player has a cool-looking ship to shoot the bad guys (and the bad guys have fearsome-looking ships).
You can load a Sprite or create a new one through the Editor (see “Making Things Sparkle with Sprites,” earlier in this chapter, for more information).
For example, say you have two balls in a Room and they collide. You would expect them to bounce off each other as if they were balls in real life. But if one of the balls is not Solid, then the one ball might appear to roll right through the other as if it were made of air.
The Object is not destroyed even if the player leaves one Room and enters another. The only way to destroy a Persistent Object is to do so explicitly through Events and Actions.
See Chapter 12 for more on using physics.
The Depth field enables you to place Objects over other Objects.
When you make a child Object, that Object inherits the properties of the parent Object.
If you don’t do this, GameMaker uses the Mask of the Sprite you assigned to the Object.
See Chapter 3 for details on Events.
See Chapter 4 for details on Actions.
When you finish creating your Objects, you’re ready to place the Objects in the Room, so that you can create Instances of those Objects within the game. You may have a single Object that represents a bad guy, but you can create several Instances of that one Object within the game; in that way, you can create many of the same bad guy to attack the player. I go into more detail on Rooms at the end of this chapter.
If you think the magic only happens in the, um, kitchen, then does GameMaker have a Room for you! GameMaker has a feature called Rooms. A Room is where you place all the different parts of your game. After you finish creating and refining your resources — Sounds, Sprites, Objects (configured with Actions and Events) — you’re ready to place Instances of your Objects in the Room. But first you have to create one.
To create a new Room, click the Create a Room icon (which looks like a white rectangle; see Figure 2-21). The Room Properties window opens (see Figure 2-22).
The Room Properties window has several tabs of features:
To place an Object in a Room, follow these steps:
The Room Properties window appears (refer to Figure 2-22).
The name of the Object appears in the field, and you see that Object’s assigned Sprite in the top corner of the window.
The Sprite for the Object appears where you click. If you’re placing an Object without an assigned Sprite, you see a little blue circle with a question mark in it.
18.226.163.229