โœฆ JVDesignStudio ยท No Sign-Up Required

GameMaker (GML) Cheat Sheet

A one-page printable reference for variables, events, movement, collision and instances the most-used GML snippets in GameMaker. Pin it next to your monitor!

๐Ÿ“ฆ Variables

// instance variable (Create Event)
hp = 100;
move_speed = 4;

// global variable, accessible anywhere
globalvar score;
global.score = 0;

// local variable, this scope only
var dist = point_distance(x, y, target.x, target.y);

Use global. for values shared across all objects, like score or game state.

โš™๏ธ Events

CreateRuns once when the instance is spawned
StepRuns every frame logic, input, movement
DrawRuns every frame drawing only
CollisionRuns when this instance touches another object
DestroyRuns once when the instance is destroyed
Alarm[0]Runs once when its countdown reaches 0

๐Ÿƒ Movement

// direct speed/direction
direction = 90;
speed = 4;

// component speeds
hspeed = 3;
vspeed = -2;

// move toward a point smoothly
move_towards_point(target.x, target.y, 4);

// simple keyboard movement
hspeed = (keyboard_check(vk_right) - keyboard_check(vk_left)) * move_speed;

๐Ÿ’ฅ Collision

if (place_meeting(x, y, obj_wall)) {
    // touching a wall at current position
    move_bounce_solid(true);
}

var hit = instance_place(x, y, obj_enemy);
if (hit != noone) {
    instance_destroy(hit);
}

if (collision_rectangle(x-16, y-16, x+16, y+16, obj_spike, false, true)) {
    hp -= 10;
}

๐Ÿงฑ Instances

// spawn a new instance on a layer
instance_create_layer(x, y, "Instances", obj_bullet);

// destroy this instance
instance_destroy();

// run code on every instance of a type
with (obj_enemy) {
    hp -= 5;
}

๐ŸŽจ Drawing

// Draw Event
draw_sprite(spr_player, image_index, x, y);

draw_set_color(c_white);
draw_text(10, 10, "Score: " + string(global.score));

draw_set_color(c_red);
draw_rectangle(x-16, y-16, x+16, y+16, false);

๐Ÿ” Control Flow

if (hp <= 0) {
    instance_destroy();
} else if (hp < 20) {
    show_debug_message("Low HP!");
} else {
    show_debug_message("OK");
}

for (var i = 0; i < 5; i++) { }
while (ammo > 0) { ammo--; }

switch (state) {
    case "idle": sprite_index = spr_idle; break;
    case "run":  sprite_index = spr_run;  break;
    default: break;
}

๐Ÿ› ๏ธ Common Patterns: Top-Down Movement + Shooting

// --- Create Event ---
move_speed = 4;
fire_rate = 20;
fire_timer = 0;

// --- Step Event ---
var mx = (keyboard_check(vk_right) - keyboard_check(vk_left));
var my = (keyboard_check(vk_down) - keyboard_check(vk_up));
hspeed = mx * move_speed;
vspeed = my * move_speed;

fire_timer -= 1;
if (mouse_check_button(mb_left) && fire_timer <= 0) {
    var ang = point_direction(x, y, mouse_x, mouse_y);
    var b = instance_create_layer(x, y, "Instances", obj_bullet);
    b.direction = ang;
    b.speed = 10;
    fire_timer = fire_rate;
}

// --- obj_bullet Collision Event with obj_enemy ---
instance_destroy(other);
instance_destroy(self);

Want to build a whole game?

Follow one of our free step-by-step workshops in the Workshop hub.

๐Ÿ”ง Browse Workshops โ†’