GameMaker Studio 2D Platformer Tutorial – Full Game in One Hour
Your platformer already runs, so now you confirm the camera, add one moving hazard that respawns the player, and package a build someone else can open.
This is the finish-and-ship pass, not the platformer build tutorial. You will not write movement, jumping, or wall collision here. This article assumes your player already moves, jumps, lands on walls, and that your room is wider than the screen.
If your project does not do those things yet, stop and get there first. Everything below sits on top of a working player.
What you start with
You need three things in place before you begin:
- A player object, called
obj_playerhere, with working movement and collision in its Step event. - A solid object, called
obj_wallhere, that the player stands on. - One room that is wider than the view.
If your names differ, swap them into the code as you go.
Part 1: Confirm the camera follows
Do not assume the camera works because you set it up once. Test it on purpose.
Open your room and look at the room settings in the Inspector. The current GameMaker manual describes viewports and cameras as part of the room’s properties. Check these in order:
- Viewports are enabled.
- Viewport 0 is set to visible.
- The camera size is smaller than the room.
- The object to follow is your player.
Now prove it in the running game. Add a Draw GUI event to obj_player and type:
var _cx = camera_get_view_x(view_camera[0]);
var _cy = camera_get_view_y(view_camera[0]);
draw_text(8, 8, "cam: " + string(_cx) + ", " + string(_cy));
The manual lists camera_get_view_x and camera_get_view_y as returning the position of a camera, and view_camera[0] as the camera assigned to viewport 0. Draw GUI draws on top of the game window, so the text stays in the corner while the world scrolls.
Run the game and walk right. The first number should grow. Walk back. It should shrink. Jump on a high platform. If your room is taller than the view, the second number should change too.
If both numbers stay at zero, your viewport is not active. Recheck the four settings above.
Once you have confirmed it, delete this Draw GUI event or comment it out. It is a debug check, not part of your game.
Part 2: Add one moving hazard
A still spike is easy to avoid. A hazard that moves forces the player to time a jump, which tests your camera and collision at the same time. You will build one patrolling saw.
Make the sprite and object
- Create a sprite called
spr_saw, 32 by 32, filled with a bright color. - Set its origin to match your other sprites so it lines up on the grid.
- Create an object called
obj_sawand give itspr_saw.
Make it patrol
Open obj_saw and add a Create event:
dir = 1; // 1 moves right, -1 moves left
spd = 2; // pixels per step
Add a Step event:
if (place_meeting(x + dir * spd, y, obj_wall)) {
dir = -dir;
}
x += dir * spd;
Before it moves, the saw checks the spot ahead. If that spot overlaps a wall, it turns around. Otherwise it moves forward.
In your room, place the saw on a floor with a wall block at each end of its path. The two blocks act as bumpers. Without them, the saw will slide off the platform and float.
Make it respawn the player
Here is where this hazard differs from a spike that restarts the level. Restarting the room resets everything. A respawn only moves the player back to the start, which feels quicker and keeps the saw moving.
Open obj_player and add a Collision event with obj_saw:
x = xstart;
y = ystart;
hsp = 0;
vsp = 0;
xstart and ystart are built-in variables that hold the position where the instance was created. Resetting your speed variables stops the player from flying off with leftover momentum. If your speed variables have different names, use yours.
Test the hazard
Run the game and check:
- The saw moves back and forth between the two bumpers.
- Touching the saw sends you to your start position.
- The camera jumps back with you after a respawn.
- You can still jump over the saw with good timing.
If the saw stops dead, it is probably starting inside a wall. Move it a few pixels away. If the player respawns inside the floor, raise the player’s start position in the room.
Part 3: Export a Windows build
The current manual describes exporting as “creating a final executable package.” Follow these steps for the Windows target, and match the manual for anything that looks different in your version.
Set your game options first
Open the Game Options for Windows. The manual describes a General page with these items:
- Product Information. The name, company, and version shown by Windows. Fill it out fully.
- Install location. A choice of the local app data or app data folder for the game package.
- Copy exe to output folder. The manual says you should rarely need it. It exists for projects that use DLLs. Leave it off.
- Enable Steam. Leave it off unless you are building for Steam and have set it up.
- Disable file system sandbox. The manual recommends keeping the sandbox, so leave this unchecked.
The Game Options pages also hold settings for icons, graphics, and other details. If you see a checkbox not listed here, read its entry in the current manual before you change it. When in doubt, leave the default.
Build the package
- Make sure Windows is your selected target in the IDE.
- Click Create Executable, or choose it from the Build menu.
- Choose between an installer and a zip package.
- Pick a save location and a file name, then save.
The manual explains the difference. An installer is a single executable that installs your game. A zip holds all your game files and must be extracted before the game runs. For sharing with a friend, the zip is usually simpler.
There is also a Remember Packaging Option checkbox. If you tick it, GameMaker stops asking and uses your choice every time. The manual says you can reset that in the Windows preferences.
The manual also notes that the Windows target builds 64-bit executables, with separate options for Arm64 Windows.
Part 4: Test the build like a stranger
Do not test only on the computer that made it. If you can, copy the zip to another Windows machine.
- Extract the zip into a new folder.
- Run the game from there.
- Walk the whole level. Hit the saw on purpose. Reach the end.
- Close the game and open it again.
Write down anything that differs from running in the IDE. Missing files, a wrong window size, or a crash on start all point to settings you should check in the manual.
Where you are now
You have a camera you confirmed with numbers, a hazard that moves and respawns the player, and a build that runs outside GameMaker. The next step is up to you. Add a second hazard, or hand the zip to one player and watch them play without helping.