-
Notifications
You must be signed in to change notification settings - Fork 0
Tutorial Platformer
Select your language / Choisissez votre langue / Wählen Sie Ihre Sprache:
English | Français | Deutsch | Italiano | Español | Português | Slovenščina | Українська | Русский
In this tutorial, you'll create a Platformer Game - a side-scrolling action game where the player runs, jumps, and navigates platforms while avoiding hazards and collecting coins. This classic genre is perfect for learning gravity, jumping mechanics, and platform collision.
What you'll learn:
- Gravity and falling physics
- Jump mechanics with ground detection
- Platform collision (landing on top)
- Left/right movement
- Collectibles and hazards
Difficulty: Beginner Preset: Beginner Preset
- The player is affected by gravity and falls down
- The player can move left and right
- The player can jump when standing on ground
- Platforms stop the player from falling through
- Collect coins for points
- Reach the flag to complete the level
| Element | Purpose |
|---|---|
| Player | The character you control |
| Ground/Platform | Solid surfaces to stand on |
| Coin | Collectible items for score |
| Spike | Hazard that hurts the player |
| Flag | Goal that ends the level |
- In the Resource Tree, right-click on Sprites and select Create Sprite
- Name it
spr_player - Click Edit Sprite to open the sprite editor
- Draw a simple character (rectangle with face, or stick figure)
- Use a bright color like blue or red
- Size: 32x48 pixels (taller than wide for a character)
- Click OK to save
- Create a new sprite named
spr_ground - Draw a grass/dirt platform tile
- Use brown and green colors
- Size: 32x32 pixels
- Create a new sprite named
spr_platform - Draw a floating platform (wood or stone)
- Size: 64x16 pixels (wide and thin)
- Create a new sprite named
spr_coin - Draw a small yellow/gold circle
- Size: 16x16 pixels
- Create a new sprite named
spr_spike - Draw triangle spikes pointing up
- Use gray or red colors
- Size: 32x32 pixels
- Create a new sprite named
spr_flag - Draw a flag on a pole
- Use bright colors (green flag, brown pole)
- Size: 32x64 pixels
The ground is a solid platform that stops the player from falling.
- Right-click on Objects and select Create Object
- Name it
obj_ground - Set the sprite to
spr_ground - Check the "Solid" checkbox
- No events needed
Platforms work the same as ground but can be placed in the air.
- Create a new object named
obj_platform - Set the sprite to
spr_platform - Check the "Solid" checkbox
- No events needed
Tip: You can make the platform a child of obj_ground to share the same collision behavior.
The player is the most complex object with gravity, jumping, and movement.
- Create a new object named
obj_player - Set the sprite to
spr_player
Event: Create
- Add Event → Create
- Add Action: Control → Execute Code
// Movement variables
hspeed_max = 4; // Maximum horizontal speed
vspeed_max = 10; // Maximum fall speed
jump_force = -10; // Jump strength (negative = up)
gravity_force = 0.5; // How fast we fall
// Current speeds
hsp = 0;
vsp = 0;
// State
on_ground = false;Event: Step
- Add Event → Step → Step
- Add Action: Control → Execute Code
// === HORIZONTAL MOVEMENT ===
// Get input
var move_input = keyboard_check(vk_right) - keyboard_check(vk_left);
// Set horizontal speed
hsp = move_input * hspeed_max;
// === GRAVITY ===
// Apply gravity
vsp += gravity_force;
// Cap fall speed
if (vsp > vspeed_max) {
vsp = vspeed_max;
}
// === GROUND CHECK ===
// Check if we're on ground (1 pixel below us)
on_ground = place_meeting(x, y + 1, obj_ground);
// === JUMPING ===
// Jump if on ground and pressing up/space
if (on_ground && (keyboard_check_pressed(vk_up) || keyboard_check_pressed(vk_space))) {
vsp = jump_force;
}
// === HORIZONTAL COLLISION ===
if (place_meeting(x + hsp, y, obj_ground)) {
// Move as close as possible
while (!place_meeting(x + sign(hsp), y, obj_ground)) {
x += sign(hsp);
}
hsp = 0;
}
x += hsp;
// === VERTICAL COLLISION ===
if (place_meeting(x, y + vsp, obj_ground)) {
// Move as close as possible
while (!place_meeting(x, y + sign(vsp), obj_ground)) {
y += sign(vsp);
}
vsp = 0;
}
y += vsp;Coins add to the score when collected.
- Create a new object named
obj_coin - Set the sprite to
spr_coin
Event: Collision with obj_player
- Add Event → Collision → obj_player
- Add Action: Score → Set Score
- New Score:
10 - Check "Relative"
- New Score:
- Add Action: Main1 → Destroy Instance
- Applies to: Self
Spikes hurt the player and restart the level.
- Create a new object named
obj_spike - Set the sprite to
spr_spike
Event: Collision with obj_player
- Add Event → Collision → obj_player
- Add Action: Main2 → Show Message
- Message:
Ouch! You hit a spike!
- Message:
- Add Action: Main1 → Restart Room
The flag ends the level when the player reaches it.
- Create a new object named
obj_flag - Set the sprite to
spr_flag
Event: Collision with obj_player
- Add Event → Collision → obj_player
- Add Action: Main2 → Show Message
- Message:
Level Complete! Score:+ string(score)
- Message:
- Add Action: Main1 → Next Room (or Restart Room for single level)
The game controller displays the score.
- Create a new object named
obj_game_controller - No sprite needed
Event: Draw
- Add Event → Draw → Draw
- Add Action: Control → Execute Code
draw_set_color(c_white);
draw_text(10, 10, "Score: " + string(score));
// Optional: Draw lives
// draw_text(10, 30, "Lives: " + string(global.lives));- Right-click on Rooms and select Create Room
- Name it
room_level1 - Set the room size (e.g., 800x480)
- Enable "Snap to Grid" and set grid to 32x32
Build your level following these guidelines:
-
Create ground - Place
obj_groundalong the bottom -
Add platforms - Place
obj_platformin the air for jumping challenges - Add gaps - Leave spaces in the ground (pits)
- Place coins - Scatter them on platforms and in hard-to-reach spots
- Add spikes - Place near pits or on platforms for challenge
- Place the flag - At the end of the level
- Place the player - At the start (left side)
- Add game controller - Anywhere (it's invisible)
F
===
C C
===== =====
C C
===== X X X =====
P C
====== === === === === === ===== ======
GGGGGG GGG GGG GGG GGGGGGGG
G = Ground P = Player F = Flag C = Coin
X = Spike === = Platform
- Click Run or press F5 to test
- Use Left/Right arrows to move
- Press Up or Space to jump
- Collect coins for points
- Avoid spikes!
- Reach the flag to win!
In the Step event, add this after jump code:
// Variable jump - release early for short jump
if (vsp < 0 && !keyboard_check(vk_up) && !keyboard_check(vk_space)) {
vsp = max(vsp, jump_force / 2);
}In Create event:
can_double_jump = true;In Step event (modify jump section):
if (keyboard_check_pressed(vk_up) || keyboard_check_pressed(vk_space)) {
if (on_ground) {
vsp = jump_force;
can_double_jump = true;
} else if (can_double_jump) {
vsp = jump_force;
can_double_jump = false;
}
}- Create
obj_moving_platformas a child ofobj_platform
Event: Create
move_distance = 100;
start_x = x;
hspeed = 2;Event: Step
if (x > start_x + move_distance) hspeed = -2;
if (x < start_x) hspeed = 2;- Create
obj_enemywith a simple AI
Event: Create
hspeed = 2;Event: Collision with obj_ground (horizontal)
hspeed = -hspeed; // Reverse at wallsEvent: Collision with obj_player
// Check if player is above (stomping)
if (other.y < y - 16) {
instance_destroy();
with (other) { vsp = jump_force / 2; }
} else {
room_restart(); // Player dies
}In obj_game_controller Create event:
if (!variable_global_exists("lives")) {
global.lives = 3;
}When player dies:
global.lives -= 1;
if (global.lives <= 0) {
show_message("Game Over!");
global.lives = 3;
room_goto_first();
} else {
room_restart();
}| Problem | Solution |
|---|---|
| Player falls through ground | Check that obj_ground has "Solid" checked |
| Player can't jump | Verify on_ground check is working; ground must be solid |
| Player gets stuck in walls | Make sure collision code moves pixel by pixel |
| Jump feels floaty | Increase gravity_force or make jump_force more negative |
| Jump feels too weak | Decrease gravity_force or make jump_force more negative |
Congratulations! You've created a platformer game! You learned:
- Gravity physics - Applying constant downward force
- Jump mechanics - Setting negative vertical speed when on ground
-
Ground detection - Using
place_meetingto check what's below - Collision handling - Moving pixel by pixel to walls
- Hazards - Creating objects that restart the level
- Level design - Building platforming challenges
- Wall Jump - Allow jumping off walls
- Dash Move - Quick horizontal burst of speed
- Crumbling Platforms - Platforms that fall after stepped on
- Checkpoints - Save progress mid-level
- Boss Battle - Add a final enemy with multiple hits
- Tutorials - More game tutorials
- Beginner Preset - Overview of beginner features
- Tutorial: Maze - Create a maze navigation game
- Tutorial: Breakout - Create a brick breaker game
- Event Reference - Complete event documentation