© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2023
B. TyersGameMaker Fundamentalshttps://doi.org/10.1007/978-1-4842-8713-2_12

12. Rooms

Ben Tyers1  
(1)
Worthing, West Sussex, UK
 

Rooms are where your game takes place. This is where you place your instances for the game.

Most games will have more than one room. Rooms can be used for certain things:
  • Splash Screen – Showing your logo and setting game variables

  • Menu – A selection screen where player can set difficulty and play a level

  • Shop – A place where a player can spend coins they have collected

  • Game Levels – Where the action happens – there may be many of these

  • Boss Levels – A special (usually hard) level between stages

  • Game Over – Shows the player’s final score

Room backgrounds can be simple, or animated, such as using a parallax effect to create depth. A parallax effect is when different background layers move at different speeds, creating an illusion of depth within your game.

You place your instances in the room, where they run and react to each other, or for example to the player’s input.

Room Editor

GameMaker has a powerful room editor, allowing you to set and customize it as required.

In the room you can
  • Set code that executes when the room starts.

  • Set a background color, or sprite(s) as the background.

  • Add tiles for complex backgrounds, allow you to “paint” your level by placing individual tiles.

  • Set up views (when you only want to show part of the room at a time).

  • Name the room and set the dimensions.

Make a new project and load in a sprite for use as a background, and set the name as shown in Figure 12-1. Backgrounds are loaded in the same way as sprites:

A screenshot of left panel shows name: bg_1; image: size- W:1024, H:1024; edit image; import. The panel on the right reads 30 frames per second 0 by 0 top left and a sprite.

Figure 12-1

Loading a sprite to use as a background

Note

For naming purposes, you should use a prefix bg_ which allows you to quickly know what the asset will be used for.

Make a new room and set the background you just created, with settings shown in Figure 12-2.

A screenshot shows a tab that reads room editor which in turn highlights a drop-down menu that reads layers – room example.

Figure 12-2

Setting a background

You can also make the background move, for example, to the left, great if you are doing a space-shooter type game.

Change the settings to that shown in Figure 12-3.

A screenshot titled, background layer properties – room example shows several options selected in the following order.

Figure 12-3

Making a background move to the left

If you test your game, the background will move to the left. Some commonly used code for room controls are shown in the following:
room_goto(room_name);
will go to the room with the given name.
room_goto_next();
to go to the next room (based on order in the Room Manager).
room_goto_previous();
to go to the previous room (again based on the room order).
room_restart();

restarts the room you are currently in.

Basic Projects

  1. A)

    Set up a splash screen that plays a sound and then goes to the menu room after five seconds.

     
  2. B)

    Create a menu that has three clickable objects. Clicking each one takes you to a different room.

     

Advance Project

  1. C)

    Create two rooms, A B. Visualize them as:

     

A B

Make the player wrap up and down in each room. Allow player to move between them, placing the player on the correct side of the room, as shown in Figure 12-4.

An illustration shows two adjacent boxes labeled room A on the left and room B on the right.

Figure 12-4

Showing project visually

Useful Functions

room_height()
room_width()

Both of the preceding variables return the height/width of the current room. These variables can then be used, for example, to draw a border or place instances to prevent the player from leaving the room when tied with some collision code.

Summary

You should now understand how to create and set up rooms. You understand which room will run first. You know how to traverse between rooms and set up a basic background.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.161.129