While GML Visual is excellent for prototyping, GML Code is faster to write, easier to debug, and necessary for complex systems like procedural generation, advanced AI, and network multiplayer. Transitioning to GML Code removes all creative limitations. 2. Core Concepts and Syntax Basics
// 1. SETUP // Calculate the offset based on angle. // We use lengthdir to push the "back" face behind the "front" face. var _dir = _angle + 90; // Adjust so 0 degrees is "up" var _x_off = lengthdir_x(_depth, _dir); var _y_off = lengthdir_y(_depth, _dir);
A staple of 2D game design is pixel-perfect collision detection. While GameMaker has built-in variables like speed and direction , writing custom movement algorithms offers much higher control.
Two-dimensional arrays, ideal for tactical maps, pathfinding graphs, or inventory grids.
// 1. GET USER INPUT var _key_left = keyboard_check(vk_left) || keyboard_check(ord("A")); var _key_right = keyboard_check(vk_right) || keyboard_check(ord("D")); var _key_jump = keyboard_check_pressed(vk_space); // 2. CALCULATE MOVEMENT var _move = _key_right - _key_left; hsp = _move * walk_speed; // Horizontal Speed vsp += grv; // Vertical Speed / Gravity (Add gravity every frame) // 3. JUMP CHECK // check if standing on a solid collision object if (place_meeting(x, y + 1, obj_solid)) && (_key_jump) vsp = -jump_speed; // 4. HORIZONTAL COLLISION DETECTION if (place_meeting(x + hsp, y, obj_solid)) // Move flush to the wall pixel-by-pixel while (!place_meeting(x + sign(hsp), y, obj_solid)) x += sign(hsp); hsp = 0; // Stop moving horizontally x += hsp; // Apply horizontal movement // 5. VERTICAL COLLISION DETECTION if (place_meeting(x, y + vsp, obj_solid)) // Move flush to the floor/ceiling pixel-by-pixel while (!place_meeting(x, y + sign(vsp), obj_solid)) y += sign(vsp); vsp = 0; // Stop moving vertically y += vsp; // Apply vertical movement Use code with caution. Variables needed in the Create Event for this script: gamemaker studio 2 gml
What (e.g., top-down RPG, platformer, puzzle) are you building?
While GML Visual (the engine’s drag-and-drop system) is fantastic for prototyping, it can quickly become clunky as your game grows in complexity. Transitioning to GML offers several undeniable advantages:
GameMaker Studio 2 (GMS2) remains a popular engine for indie developers and hobbyists thanks to its approachable visual tools and powerful scripting language: GameMaker Language (GML). This post walks through what GML is, why it matters, core language features, workflow tips, and resources to help you build clean, maintainable games in GMS2.
GML looks up variables slowly. Use var for temporary variables. While GML Visual is excellent for prototyping, GML
switch (current_state) case "idle": scr_enemy_idle(); break; case "chase": scr_enemy_chase(); break; default: show_debug_message("Unknown state!"); break; Use code with caution.
The invisible "blueprints" that contain logic, code, and variables.
Accessible by any object, anywhere in the game. Declared using the global. prefix or a globalvar statement. global.gold_count = 0; global.game_paused = false; Use code with caution. Data Types
To start coding with GML, you’ll typically work with these fundamental elements: Core Concepts and Syntax Basics // 1
Design your levels using tiles, sprites, and objects. 2. Coding Basic Systems Most GML content starts with core mechanics:
Whether you are building a pixel-art platformer, a bullet-hell shooter, or a complex RPG, understanding GML is the difference between a generic prototype and a polished, commercial release. This article is your deep dive into GML—from basic variables to advanced optimization techniques.
Used to store data like player health or movement speed.