2 Gml — Gamemaker Studio
GameMaker Studio 2 and its scripting language, GML, provide a powerful, flexible, and surprisingly deep environment for 2D game development. From its beginner-friendly event-driven model to its advanced capabilities with constructors and shaders, GML can grow with you as a developer.
GML is designed to be easy to learn. If you have any experience with languages like JavaScript, C, or Java, you will find GML's syntax immediately familiar. In its recent iterations (particularly version 2.3+), GML has adopted many features common to modern languages, such as methods, constructors, and lightweight anonymous functions, bringing it closer to the capabilities of languages like JavaScript.
// Get sprite dimensions var _w = sprite_get_width(_sprite); var _h = sprite_get_height(_sprite); var _xc = sprite_get_xoffset(_sprite); var _yc = sprite_get_yoffset(_sprite);
: Unique to a specific object instance, declared without keywords (e.g., hp = 100; ). They persist for the lifetime of that instance. gamemaker studio 2 gml
Right-click in the Asset Browser, select to create a script asset. In the editor, you can write your function:
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:
The heart of this review is GML. If you are on the fence, this is what you need to know: GameMaker Studio 2 and its scripting language, GML,
You can now store functions in variables and pass them around.
Here is a quick example of how simple it is to move a character using GML. You would place this code inside the of your player object.
lengthdir_x / lengthdir_y : Essential GML math functions that prevent diagonal movement from being faster than horizontal or vertical movement. 5. Advanced GML Concepts If you have any experience with languages like
GML dynamically handles types, but you will primarily deal with: Integers and floats (e.g., 1 , -50 , 3.14 ). Strings: Text wrapped in quotes (e.g., "Hello World" ). Booleans: true or false . Arrays: Collections of data indexed by numbers.
Variables that persist across the entire game, making them perfect for holding player scores, inventory data, or current game states. 2. Objects and Instances