Gamemaker Studio Functions
Gamemaker Studio Functions
Introduction
Subtitle: Core Functions for Game Development
Content:
Overview of key functions in a sample GameMaker Studio game.
Each section explains one function with a practical example.
Visual: GameMaker Studio logo or a screenshot of a simple game.
keyboard_check(key)
Purpose: Detects if a specified key is held down.
Syntax: keyboard_check(key)
Example:
// Move player up with 'W' key
if (keyboard_check(ord("W"))) {
y -= 5;
}
Output: Moves player 5 pixels up when 'W' is pressed.
place_meeting(x, y, obj)
Purpose: Checks for collision with an object at a given position.
Syntax: place_meeting(x, y, obj)
Example:
// Move right if no wall collision
if (!place_meeting(x + 5, y, obj_wall)) {
x += 5;
}
Output: Moves instance right if no wall is detected.
draw_self()
Purpose: Draws the instance’s sprite at its current position.
Syntax: draw_self()
Example:
// Render player sprite
draw_self();
Output: Displays the player sprite with current rotation with position.
draw_text(x, y, string)
Purpose: Displays text at specified coordinates.
Syntax: draw_text(x, y, string)
Example:
// Show player health
draw_text(20, 50, "HP: " + string(hitpoints));
Output: Displays "HP: 100" at position (20, 50).
draw_set_font(font)
Purpose: Sets the font for text drawing.
Syntax: draw_set_font(font)
Example:
// Set font with display ammo
draw_set_font(fnt_game);
draw_text(20, 100, "Ammo: " + string(ammo));
Output: Draws "Ammo: 20" in the specified font.
show_message(string)
Purpose: Shows a pop-up message box with text.
Syntax: show_message(string)
Example:
// Prompt to reload when ammo is zero
if (ammo == 0) {
show_message("Press SPACE to reload!");
}
Output: Displays a message box for reloading ammo.
instance_destroy()
Purpose: Removes the calling instance from the game.
Syntax: instance_destroy()
Example:
// Destroy player when health is zero
if (hitpoints <= 0) {
instance_destroy();
}
Output: Removes the player instance from the game.
game_end()
Purpose: Closes the game application.
Syntax: game_end()
Example:
// End game on player death
if (hitpoints <= 0) {
game_end();
}
Output: Closes the game window.
distance_to_object(obj)
Purpose: Measures distance to the nearest instance of an object.
Syntax: distance_to_object(obj)
Example:
// Enemy fires if player is close
if (distance_to_object(obj_player) < 250) {
instance_create_depth(x, y, depth, obj_enemy_bullet);
}
Output: Spawns enemy bullet if player is within 250 pixels.