Sprites, Objects, and Rooms
Sprites: Creating Visual Elements
Sprites are the visual representations of your game objects. In this section, we will learn how to create and edit sprites using the Sprite Editor in Game Maker Studio. We will focus on drawing our own sprites rather than importing them, fostering creativity and a deeper understanding of the tools available.
Creating a Sprite
-
Open the Sprite Editor:
- In the Resource Tree, right-click on the “Sprites” folder.
- Select “Create Sprite” from the context menu. This will open a new sprite resource.
-
Name Your Sprite:
- In the Properties Panel, give your sprite a meaningful name (e.g.,
spr_pacman
,spr_ghost
,spr_powercircle
,spr_maze
).
- In the Properties Panel, give your sprite a meaningful name (e.g.,
-
Edit Image:
- Click on the “Edit Image” button to open the Sprite Editor. This is where you will draw your sprite.
Using the Sprite Editor Tools
The Sprite Editor provides various tools to help you create and modify your sprites. Here’s a look at the main tools you will use:
-
Paint Tool:
- The Paint Tool is used to draw freehand on the canvas. You can select a color from the palette and click and drag to draw.
- To change the brush size, look for the brush size options in the toolbar or use the keyboard shortcuts (usually the ”[” and ”]” keys).
-
Eraser Tool:
- The Eraser Tool works similarly to the Paint Tool but removes pixels instead of adding them. Use it to correct mistakes or refine your drawing.
- Adjust the eraser size using the same methods as for the Paint Tool.
-
Line Tool:
- The Line Tool allows you to draw straight lines. Click to start the line, drag to the desired endpoint, and release to complete the line.
- You can adjust the thickness of the line in the toolbar.
-
Rectangle Tool:
- The Rectangle Tool is used to draw rectangles. Click and drag to define the size of the rectangle.
- Adjust the thickness of the rectangle’s border in the toolbar or choose to fill the rectangle with a solid color.
Drawing Our Sprites
Now that you are familiar with the Sprite Editor tools, let’s start drawing our game elements. Remember to use your creativity and have fun while drawing your sprites!
Drawing Pac-Man
-
Create a New Sprite:
- Name it
spr_pacman
. - Open the Sprite Editor and select a suitable size for the canvas (e.g., 32x32 pixels).
- Name it
-
Draw Pac-Man:
- Use the Paint Tool to draw a yellow circle for Pac-Man.
- Use the Line Tool to create a “mouth” by drawing a triangular cut-out. This cut-out gives Pac-Man his iconic look, appearing as if he is always chomping.
Drawing the Ghosts
-
Create Four New Sprites:
- Name them
spr_ghost_red
,spr_ghost_pink
,spr_ghost_blue
,spr_ghost_orange
. - Open each sprite in the Sprite Editor with a canvas size of 32x32 pixels.
- Name them
-
Draw the Ghosts:
- Use the Paint Tool to draw the ghost body shapes in their respective colors. Start with a rounded top and finish with a wavy bottom to resemble the classic ghost shape.
- Add eyes using the Paint Tool with a white color for the eyeballs and a blue or black color for the pupils. This gives the ghosts a playful and animated look.
Drawing Power Circles
-
Create a New Sprite:
- Name it
spr_powercircle
. - Use a canvas size of 16x16 pixels.
- Name it
-
Draw Power Circles:
- Use the Paint Tool to draw a small, white circle. The power circles should be distinct enough to be easily recognized during gameplay.
Drawing the Maze
-
Create a New Sprite:
- Name it
spr_maze
. - Use a larger canvas size (e.g., 256x256 pixels).
- Name it
-
Draw the Maze:
- Use the Line Tool or Rectangle Tool to draw the walls of the maze. Ensure that the paths are wide enough for Pac-Man and the ghosts to move through.
- Remember to only use the Line Tool or Rectangle Tool to maintain consistency and precision in the maze layout. The maze should be designed in a way that provides a challenging yet fun experience for the player.
Tips for Drawing Sprites
- Use Consistent Colors: Stick to a consistent color palette to maintain a cohesive look for your game.
- Keep It Simple: Simple designs are often more effective, especially for small sprites where too much detail can become confusing.
- Experiment: Don’t be afraid to experiment with different shapes and styles. You can always use the Eraser Tool to make adjustments.
By following these steps and utilizing the tools available in the Sprite Editor, you will create the visual elements needed for your Pac-Man clone. In the next section, we will bring these sprites to life by creating objects and defining their behaviors.
Level 1 Exercises
Exercise 1: Create sprites for Pac-Man, the power circles, maze, and ghosts in Game Maker.
Exercise 2: Draw Pac-Man, the power circles, maze, and ghosts using the Game Maker sprite editor.
Level 2 Exercises
Exercise 1: Create all the sprites for the game you planned in Game Maker.
Exercise 2: Draw the sprites for the game you planned in Game Maker.
Level 3 Exercises
Exercise 1: Create and draw all the sprites for the game you planned and use Game Maker Language to print information about each of the sprites.
Objects: Bringing Sprites to Life
Objects are the interactive elements of your game. They use sprites for their visual representation and can have behaviors and interactions defined by events and actions. In this section, we will learn how to create objects in Game Maker Studio, set their sprites, and configure their collision masks.
Creating an Object
-
Open the Object Editor:
- In the Resource Tree, right-click on the “Objects” folder.
- Select “Create Object” from the context menu. This will open a new object resource.
-
Name Your Object:
- In the Properties Panel, give your object a meaningful name (e.g.,
obj_pacman
,obj_ghost_red
).
- In the Properties Panel, give your object a meaningful name (e.g.,
-
Set the Sprite:
- In the Object Editor, assign the corresponding sprite to the object by selecting it from the “Sprite” dropdown menu.
-
Set the Collision Mask:
- In the Properties Panel, under “Collision Mask,” select “Precise (slow)”. This setting ensures that collisions are detected accurately based on the shape of the sprite.
Creating Objects for Our Sprites
Let’s create objects for all the sprites we’ve drawn. Each object will be linked to a specific sprite and configured to interact correctly within the game.
Creating Pac-Man Object
-
Create a New Object:
- Name it
obj_pacman
. - Assign the sprite
spr_pacman
to this object. - Set the collision mask to “Precise (slow)”.
- Name it
-
Configure Object Properties:
- In the Object Editor, you can further configure properties such as the object’s parent, depth, and persistent state. For now, we will keep these at their default settings.
Creating Ghost Objects
-
Create Four New Objects:
- Name them
obj_ghost_red
,obj_ghost_pink
,obj_ghost_blue
,obj_ghost_orange
. - Assign the corresponding ghost sprites to these objects.
- Set the collision mask to “Precise (slow)`.
- Name them
-
Configure Object Properties:
- Similar to the Pac-Man object, you can adjust properties specific to each ghost. This can include behaviors and interactions that will be defined later in the development process.
Creating Power Circle Object
-
Create a New Object:
- Name it
obj_powercircle
. - Assign the sprite
spr_powercircle
to this object. - Set the collision mask to “Precise (slow)`.
- Name it
-
Configure Object Properties:
- Ensure that the power circle object is properly set up to interact with Pac-Man. This will involve defining events and actions later on.
Creating Maze Object
-
Create a New Object:
- Name it
obj_maze
. - Assign the sprite
spr_maze
to this object. - Set the collision mask to “Precise (slow)`.
- Name it
-
Configure Object Properties:
- Since the maze will serve as the primary environment for the game, ensure that its properties allow for effective collision detection and interaction with other objects.
Level 1 Exercises
Exercise 1: Create objects for Pac-Man, the power circles, maze, and ghosts in Game Maker.
Exercise 2: Assign the correct sprites to the Pac-Man, the power circles, maze, and ghosts objects you created.
Level 2 Exercises
Exercise 1: Create the objects for the game you planned in Game Maker.
Exercise 2: Assign the correct sprites to the objects you created for the game you planned.
Level 3 Exercises
Exercise 1: Create the objects you planned for your game and assign the necessary sprites, then use Game Maker Language to print information about the objects.
Rooms: Building the Game Environment
Rooms are the game levels or screens where the action takes place. They define the structure and layout of your game world, determining where objects are placed and how they interact. In this section, we will learn how to create rooms in Game Maker Studio, add objects to them, and scale those objects if necessary. Additionally, we’ll cover how to run and test your game to ensure everything works as expected.
Creating a Room
-
Open the Room Editor:
- In the Resource Tree, right-click on the “Rooms” folder.
- Select “Create Room” from the context menu. This action will open a new room resource where you can start building your game environment.
-
Name Your Room:
- In the Properties Panel, give your room a meaningful name (e.g.,
rm_level1
). Naming your rooms appropriately helps in organizing and managing your game development process, especially as the number of rooms increases.
- In the Properties Panel, give your room a meaningful name (e.g.,
Adding Objects to the Room
Once you have created and named your room, the next step is to populate it with the objects you created earlier. This involves placing objects like Pac-Man, the ghosts, power circles, and the maze elements within the room.
-
Open the Room:
- Double-click on your newly created room (e.g.,
rm_level1
) to open the Room Editor. This will display the room’s grid where you can place and arrange your objects.
- Double-click on your newly created room (e.g.,
-
Add Objects:
- In the Room Editor, look for a toolbar that includes different layers. Select the “Instances” layer, which is used for placing interactive objects in the room.
- From the Resource Tree, drag and drop each object into the room:
obj_pacman
: Place this object at the starting position where Pac-Man will begin the game.obj_ghost_red
,obj_ghost_pink
,obj_ghost_blue
,obj_ghost_orange
: Distribute these ghost objects around the maze strategically to provide a challenging game experience.obj_powercircle
: Place these objects in specific locations where Pac-Man can collect them for power-ups.obj_maze
: Use this object to define the boundaries and pathways of the maze, ensuring that it creates a navigable environment for both Pac-Man and the ghosts.
-
Positioning Objects:
- Carefully position each object to create a balanced and engaging game layout. Ensure that the maze paths are wide enough for Pac-Man and the ghosts to move through without difficulty.
- Consider the gameplay flow and adjust the placement of objects to enhance the player’s experience.
Level 1 Exercises
Exercise 1: Add the Pac-Man object, at least 10 power circle objects, a maze object, and the ghost objects to the room in Game Maker.
Level 2 Exercises
Exercise 1: Add all the objects that you planned for your game to the room in Game Maker.
Level 3 Exercises
Exercise 1: Use Game Maker Language to create a script that prints information about the objects in the room.
Scaling Objects
Sometimes, you may need to scale objects to fit the room properly. Game Maker Studio provides tools to adjust the size of objects within the Room Editor.
-
Select an Object:
- Click on the object you want to scale within the Room Editor.
-
Use Scaling Handles:
- When you select an object, scaling handles (small squares or circles) will appear around it. Click and drag these handles to resize the object proportionally.
- Ensure that the scaled objects maintain their functionality and appearance. For example, if you scale the maze, make sure it still aligns correctly with the game grid and does not distort the gameplay.
-
Check Object Interactions:
- After scaling, verify that the objects interact correctly with each other. Adjust positions if necessary to maintain smooth gameplay.
Running the Game
Once you have added and positioned all the objects in your room, it’s time to run and test your game. This step allows you to see how the game looks and functions in real-time, identifying any areas that need adjustments.
-
Compile and Run:
- Click the green “Play” button in the toolbar to compile your game. This process converts your game project into an executable format that can be played.
- The game will open in a new window, allowing you to test the placement of objects and ensure everything appears as expected.
-
Test and Refine:
- Play through the game to evaluate the layout, object interactions, and overall gameplay experience. Take notes of any adjustments needed, such as repositioning objects, tweaking the maze layout, or adjusting object scales.
- Return to the Room Editor to make any necessary changes based on your observations. Re-run the game to test your adjustments and iterate this process until you are satisfied with the game setup.
Level 1 Exercises
Exercise 1: Run your Pac-Man game and ensure that all objects (Pac-Man, power circles, maze, and ghosts) appear where you expect them. Update your sprites and objects to fix any issues.
Level 2 Exercises
Exercise 1: Run the game you planned and ensure that all objects appear where you expect them. Update your sprites and objects to fix any issues.
Level 3 Exercises
Exercise 1: Run the game you planned in debug mode and experiment with using the debugger to identify and fix any issues.
Summary
In this section, we learned how to create rooms, add and scale objects, and test the game environment in Game Maker Studio. These steps are crucial for building the foundation of your game, ensuring that all elements are properly positioned and interact seamlessly. By testing and refining your setup, you can create a polished and engaging game experience for players.
In the next chapter, we will add behaviors and interactions to the objects, bringing the game to life with movement, collision detection, and game logic. Happy game developing!
Vocabulary Review
Term | Definition |
---|---|
Sprite | A picture or image that represents an object in a game. |
Sprite Editor | A tool in Game Maker Studio where you can draw and edit your sprites. |
Paint Tool | A tool used to draw freehand on the canvas. |
Eraser Tool | A tool used to remove pixels from your drawing. |
Line Tool | A tool that allows you to draw straight lines. |
Rectangle Tool | A tool used to draw rectangles, either filled with color or with just an outline. |
Canvas | The area where you draw your sprite. |
Properties Panel | A section in the editor where you can name your sprite and adjust other settings. |
Collision Mask | An invisible shape that determines how objects bump into each other. |
Object | An interactive element in your game that uses a sprite for its appearance and can have behaviors defined by events. |
Room | The level or screen where the game action happens. |
Resource Tree | A list in Game Maker Studio that helps you organize and access different parts of your game, like sprites and objects. |