GameMakerBlog Tutorials
What is a GameMaker Room
The official documentation of a Room can be found here and at a high level it is a container that can hold object instances and assets. There can be more than one room in your game, rooms can parents of other rooms, rooms can be added dynamically while the game is running and most importantly: Gameplay takes place in a room. Different parameters related to a room include: making a room persistent, adding layers to a room and setting viewports for the room. While this may all seem obvious to most, let us see if we can relate this to the real world and make things clearer for anyone who might be in need.
A room is like an empty plot of land, capable of holding instances of “Objects” like Houses, Animals, People, Cars, Grass, Mountains, Roads. You can define the properties of your empty piece of land:
- Width: How wide the plot is
- Top Down Game: Like looking at a map of earth and seeing the distance between the left edge of the map and some point to the right of that edge as a thin solid line. How long that line is depends on how much “Width” you have, 800px might let you see a line from Alaska to Iceland but 2048px might produce a line from Alaska to India.
- Platformer: Like standing in the middle of the street, looking ahead and behind you. How far down the street you see depends on how much “Width” you have. A width of 1024px might allow you to see 4 houses down but at 1920px you might be able to see to the end of 10 houses.
- Height: How long the plot is
- Top Down Game: Like looking at the same map of earth and seeing the distance between the top edge to some point below that. How long of a line you see on the map depends upon how much “Height” you give it. With a Height of 600px you may see from Greenland to Spain, at 1080px you might be able to see the line go all the way to South Sandwich
- Platformer: Standing in the middle of the street and seeing content above and/or below you depending on what you are standing on in the street depends on how much “Height” you give. At a height of 768px and standing directly on the street, you might be able to see airplanes in the sky above you and at 1200px you may even be able to see the sun. In contrast though, if you were standing on top of a moving truck in the middle of the street, a height of 768px may let you see the tops of buildings AND the street under the truck. It important to know that height is total content in a platformer and what is considered the “base level” of the Room determines what you can see above and below you.
- *Width and Height work together*
- It is important to point out that Width and Height work together in order to determine the entire playing field. As explained, Width can be thought of as a horizontal line between two points, Height a vertical line between two points. Together those sets of points create a rectangle, most commonly presented in the form of: x1,y1,x2,y2
- draw_rectangle(x1, y1, x2, y2, outline) is a GameMaker function that uses the common form described
- X = Width
- X1 = Starting Point = 0
- X2 = Ending Point = 1920
- Y = Height
- Y1 = Starting Point = 0
- Y2 = Ending Point = 1080
- Rectangle = 4 lines
- Line 1 = X1,Y1 to X1,Y2 = Vertical = 0,0 to 0,1080
- Line 2 = X1,Y1 to X2,Y1 = Horizontal = 0,0 to 1920,0
- Line 3 = X1,Y2 to X2,Y2 = Horizontal = 0,1080 to 1920,1080
- Line 4 = X2,Y1 to X2,Y2 = Vertical = 1920,0 to 1920,1080
- X = Width
- This Rectangle comprises the room or in our examples above: the Map or Street.
- Top Down: A Map with size: 800×600 lets us see Alaska, Canada, United States and Iceland
- Platformer: Standing on a Street that has a size of: 1024×768 you can see 4 houses down the street, the tops of those houses, smoke coming out the chimneys and airplanes in the sky.
- Persistence: Should the plot of land keep any changes that have happened during current gameplay if you leave that land and then later come back
- Situation: You demolish your starter house and then go to your neighbors plot (next room) and later come back
- ON
- Your house will still be demolished
- OFF
- Your house will be back to the initial state when you started the game
- Clear Display Buffer: Does not actually clear the display but paints the background window color a specified color at the beginning of every frame. This is like taking a blank canvas and painting it pure blue and then drawing grass on it; if you do not draw grass on certain spots of the canvas then you will see the blue background. The best visual example of this is can be found on the following official screenshot: Example
- “NOTE: As per the documentation; by default you need to select “Clear Display Buffer” in the room editor for the colour to be shown, and you can only set the colour using the function window_set_colour(). If you don’t use this function it will default to black.”
- This means the black parts between the viewports in the screenshot Example is the background display, if you enable Clear Display Buffer and choose a colour with the function: window_set_colour(colour) then those parts of the screen not covered by the viewports will be painted with the selected color.
- “NOTE: As per the documentation; by default you need to select “Clear Display Buffer” in the room editor for the colour to be shown, and you can only set the colour using the function window_set_colour(). If you don’t use this function it will default to black.”
- ViewPorts and Cameras: This is where things get complicated but at a high level a ViewPort is just like a Room, a plot of land, but instead of placing object instances you project a “View” onto it like a projector would to a screen. Using this as the example:
- ViewPort = Projection Screen, the canvas that will be used to show the Projection Image being sent from the Projector (Camera)
- Camera = Projector, the component that will construct the view of the Room and project that image onto the Projection Screen (ViewPort)
- View = The resulting image that is displayed on the Projection Screen (ViewPort)
- A detailed description can be found on the official docs: Cameras
- Object Following: This option will allow you to specify a specific object that the Camera and resulting View will stay focused on. This is just like a movie camera that follows an actor moving around the set, keeping an actor “in view” is achieved by simply selecting that actor in the Object Following dialog box. There are some points to keep in mind though:
- If you have more than one “instance” of the object you wish to follow then the results of which instance being followed will be random with a lean towards following the first object that was created. Read more here
- Vertical and Horizontal Border: This is like an invisible wall that will move the “View” when the object being followed crosses the border. Picture yourself standing in a very large dark room with just a spotlight directly overhead, the vertical and horizontal border parameters will determine when the spotlight moves to follow you. If the borders for the spotlight are exactly half of the spotlight’s total width and height; then it will follow you directly overhead as you walk and you will always be in the center of the spotlight.
- This is measured along the X axis (Horizontal Border) and the Y axis (Vertical Border) to the edges of the view (really the Camera), for example:
- Camera Settings = Width of 320, Height of 320
- Horizontal Border of 160 (Width /2 ) will keep the object in the middle of the view when moving the object to be followed right and left, provided the boundary of the Room has not been reached by the Camera; if the boundary has been reached the object will stop being followed and will instead be allowed to freely move within the screen past the Horizontal Border
- Vertical Border of 0 will let the object touch the edge of the screen when moving up or down before the View begins to move and follow the object
- Camera Settings = Width of 320, Height of 320
- A detailed picture of this can be viewed and read here
- This is measured along the X axis (Horizontal Border) and the Y axis (Vertical Border) to the edges of the view (really the Camera), for example:
- Vertical and Horizontal Speed: This will control how fast the View pans when following the object and if we continue our spotlight example we can simulate some interesting effects. Any negative value for speed results in a real-time movement of the spotlight overhead that matches your walking speed, however if the speed is a positive number but less than your current walking speed, a lag effect starts to occur as you begin moving faster than the spotlight does. If you stop walking the spotlight will catch up to you and place itself on the specified Horizontal and Vertical border parameters you set. If those values were setup for the center of the spotlight then it will once again stop with you directly in the center.
- Vertical and Horizontal Settings
- Negative Numbers (-1) = Instant real-time Camera following of the object
- Positive Number (2) = Camera will move 2 pixels per game frame
- (2) is Less than Follow Object Move Speed (4) = Results in a lag effect where the Camera “catches up” to the object, if the object never stops the Camera will never catch up
- (2) is More than the Follow Object Move Speed (1) = Instant real-time Camera following the object, Camera will not move faster than the Object that is being followed
- Vertical Speed documentation
- Horizontal Speed documentation
- Vertical and Horizontal Settings
Additional Resources
The GameMaker Community has done an amazing job explaining certain things like the Camera system and to better keep track of these guides you can find them all listed here. If there are any new resources that should be in this list, please leave a comment below and I will add them.
- Madde Michael: [GUIDE] Meet the New Camera System
- Madde Michael: [GUIDE] Getting Started with Room Layers (mostly new GML functions)
I appreciate the room explanations–they are helpful. The one thing that I don’t know about rooms and have not seen anyone address in any tutorial I’ve read so far, is what they “actually are” in terms of the instructions that make up a program. Are they memory locations? Are they allocations of memory blocks in specific areas? If we are talking about something like a sprite that is created by instructing the computer to put an image at x and y coordinates and to occupy some number of pixels on a map, that’s easy to imagine. But objects can also contain their own set of instructions relating to create/destroy, steps, etc. It *can’t* be that by putting an object instance in a room you are assigning 5 or 10 lines of code to be “placed” at an x,y coordinate covering z number of pixels–can it?
Maybe the idea is that by placing an instance of an object with code “in” a room, what is actually being done is telling the computer: “when you see this room identifier and this object instance linked, run the object instance code in this way; if it’s a different room, handle it in another way.” ??