### audio_sound_get_loop_start Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Asset_Management/Audio/Audio_Loop_Points/audio_sound_get_loop_start Gets the loop start time of a sound. ```APIDOC ## audio_sound_get_loop_start ### Description This function returns the loop start point in seconds for the given sound asset or sound instance. ### Method GET ### Endpoint /audio/sound/loop_start ### Parameters #### Query Parameters - **index** (Sound Asset or Sound Instance ID) - Required - The ID of a sound asset or a sound instance ### Request Example (No request body for GET method) ### Response #### Success Response (200) - **loop_start_time** (Real) - The loop start point in seconds. #### Response Example ```json { "loop_start_time": 1.5 } ``` ``` -------------------------------- ### gamepad_test_mapping Example - Build Custom Mapping String Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Game_Input/GamePad_Input/gamepad_test_mapping Demonstrates constructing a dynamic mapping string by iterating through instances and combining device GUID, description, and SDL-formatted input bindings. The complete mapping string is then applied to a gamepad slot using gamepad_test_mapping. ```gml var mapping = gamepad_get_guid(global.padIndex) + "," + gamepad_get_description(global.padIndex); var len = array_length(global.PadInstances); for (i = 0; i < len; i += 2) { var left = global.PadInstances[i]; var right = global.PadInstances[i+1]; mapping += "," + left.sdlLabel + ":" + right.binding; } gamepad_test_mapping(global.padIndex, mapping); ``` -------------------------------- ### Mipmapping Overview Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Drawing/Mipmapping/Mipmapping General information about mipmapping setup and configuration. This provides context on how mipmapping works and how to properly configure it in your GameMaker project. ```APIDOC ## Mipmapping Overview ### Description Mipmapping generates lower resolution versions of textures for rendering at appropriate distance levels, improving performance and visual quality. ### Prerequisites Before using mipmapping functions: 1. Enable mipmapping for required texture pages in the Texture Group Editor 2. Enable mipmapping at runtime using `gpu_set_tex_mip_enable()` ### How Mipmapping Works #### Mipmap Levels - **Level 0**: Original texture at full resolution - **Level 1**: Half the size of Level 0 - **Level 2**: Half the size of Level 1 - Pattern continues: each level is half the size of the previous #### Pixel Sampling For each mipmap level, a 2x2 block from the previous level is sampled: - Takes 4 pixels from the previous mipmap level - Creates 1 pixel for the current level - Results in texture that is half the size ### Preventing Texture Bleeding #### Border Size Configuration - Mipmapping can cause bleeding issues when sprites are close together on texture pages - Set **border size** option in Texture Group to create gaps between sprites - Border is added around each individual sprite - Example: Border size of 8 allows mipmaps to scale to sixteenth level (8 + 8 = 16 pixel gap) ### Anisotropic Filtering #### Purpose - Makes textures appear sharper when viewed at angles - Complements mipmapping for improved visual quality - Can be enabled using `gpu_set_tex_max_aniso()` or `gpu_set_tex_max_aniso_ext()` #### Usage Example Enable anisotropic filtering for sharper texture appearance: ``` gpu_set_tex_max_aniso(16); ``` ### Configuration Workflow 1. Enable mipmapping in Texture Group Editor for desired texture pages 2. Call `gpu_set_tex_mip_enable()` at runtime 3. Optionally configure mipmap levels, bias, and filtering using setter functions 4. Optionally enable anisotropic filtering for sharper results ``` -------------------------------- ### Assign Multiple Script Functions to Layer in Room Creation Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Asset_Management/Rooms/General_Layer_Functions/layer_script_end Complete example showing how to retrieve a layer ID by name and assign both begin and end script functions to it. This setup should be called once at room start, typically in room creation code or an instance's create event. ```gml var lay_id = layer_get_id("Instances"); layer_script_begin(lay_id, layer_shader_start); layer_script_end(lay_id, layer_shader_end); ``` -------------------------------- ### Set Up Particle System with Code - GameMaker Language Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Drawing/Particles/Particle_Systems/part_system_create Demonstrates creating a particle system with programmatic configuration including emitter setup, particle type definition, and proper cleanup. This example shows the complete lifecycle: creation in Create event, configuration with emitter and particle type, and destruction in Clean Up event. ```gml // Create Event part_sys = part_system_create(); part_emitter = part_emitter_create(part_sys); part_emitter_region(part_sys, part_emitter, 0, room_width, 0, room_height, ps_shape_rectangle, ps_distr_linear); part_type = part_type_create(); part_type_shape(part_type, pt_shape_disk); part_emitter_stream(part_sys, part_emitter, part_type, 2); // Clean Up Event part_system_destroy(part_sys); part_type_destroy(part_type); ``` -------------------------------- ### Initialize Particle System with Emitter and Delay Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Drawing/Particles/Particle_Emitters/part_emitter_delay Complete example demonstrating particle system setup in the Create event. Creates a particle system, emitter, and configures the emitter with a delay of 1 second before starting to stream particles. The emitter is positioned in an elliptical region and set to emit particles at intervals of 0.4 to 1.1 seconds. ```gml ps = part_system_create(); part_system_position(ps, x, y); pe = part_emitter_create(ps); part_emitter_region(ps, pe, 100, 200, 100, 200, ps_shape_ellipse, ps_distr_linear); part_emitter_delay(ps, pe, 1, 1, time_source_units_seconds); part_emitter_interval(ps, pe, 0.4, 1.1, time_source_units_seconds); pt = part_type_create(); part_emitter_stream(ps, pe, pt, 20); ``` -------------------------------- ### Create and Configure Camera with Matrix Functions in GML Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Cameras_And_Display/Cameras_And_Viewports/camera_create Creates a new camera and assigns it to a view slot, then constructs and applies view and projection matrices using matrix_build_lookat and matrix_build_projection_ortho functions. This example demonstrates the proper workflow for setting up a valid camera with required position and view size parameters. ```gml view_camera[0] = camera_create(); var _viewmat = matrix_build_lookat(640, 240, -10, 640, 240, 0, 0, 1, 0); var _projmat = matrix_build_projection_ortho(640, 480, 1.0, 32000.0); camera_set_view_mat(view_camera[0], _viewmat); camera_set_proj_mat(view_camera[0], _projmat); ``` -------------------------------- ### Create Particle System with Configured Emitter and Interval in GML Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Drawing/Particles/Particle_Emitters/part_emitter_interval Complete example demonstrating particle system initialization, emitter creation with region setup, and interval configuration for stream mode emission. The emitter waits 1 second before starting, then emits 20 particles every 0.4 to 1.1 seconds with proper resource cleanup in the Cleanup event. ```gml // Create Event ps = part_system_create(); part_system_position(ps, x, y); pe = part_emitter_create(ps); part_emitter_region(ps, pe, 100, 200, 100, 200, ps_shape_ellipse, ps_distr_linear); part_emitter_delay(ps, pe, 1, 1, time_source_units_seconds); part_emitter_interval(ps, pe, 0.4, 1.1, time_source_units_seconds); pt = part_type_create(); part_emitter_stream(ps, pe, pt, 20); // Cleanup Event part_emitter_destroy(pe); part_system_destroy(ps); part_type_destroy(pt); ``` -------------------------------- ### Complete Audio Falloff Setup Example in GameMaker Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Asset_Management/Audio/audio_falloff_set_model Full example demonstrating audio falloff model configuration followed by positional sound playback. This setup ensures a waterfall sound loops at room coordinates with proper volume attenuation based on listener distance, using exponent distance clamped falloff with specified reference and maximum distances. ```GML audio_falloff_set_model(audio_falloff_exponent_distance_clamped); audio_play_sound_at(snd_Waterfall, x, y, 0, 100, 300, 1, true, 1); ``` -------------------------------- ### wallpaper_set_config Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Live_Wallpapers/Live_Wallpapers Configures the Live Wallpaper settings for your project. This function allows you to set up the initial configuration for your wallpaper application before installation through the store. ```APIDOC ## wallpaper_set_config ### Description Configures the Live Wallpaper settings and initialization parameters for your wallpaper project. ### Function Signature ``` wallpaper_set_config(config) ``` ### Parameters - **config** (struct) - Required - A structure containing the wallpaper configuration settings ### Purpose This function is used to set up and configure Live Wallpaper functionality before the wallpaper is installed through the store. It allows you to define how your wallpaper should behave and interact with the system. ### Related Functions - wallpaper_set_subscriptions ### Notes - For detailed setup instructions, refer to the GX Live Wallpapers helpdesk article - Configuration must be set before wallpaper installation - Subject to security restrictions listed in the Live Wallpapers documentation ``` -------------------------------- ### Gamepad Functions - General Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Game_Input/GamePad_Input/Gamepad_Input Provides an overview of essential functions for checking gamepad support and device availability. ```APIDOC ## General Gamepad Functions These functions provide basic information about gamepad support and connected devices. ### `gamepad_is_supported()` **Description:** Checks if the current platform supports gamepad input. **Method:** `gamepad_is_supported() **Returns:** `true` if gamepad input is supported, `false` otherwise. ### `gamepad_is_connected(device_index)` **Description:** Checks if a specific gamepad device is connected. **Method:** `gamepad_is_connected(device_index) **Parameters:** - **device_index** (integer) - The index of the gamepad device to check. **Returns:** `true` if the device is connected, `false` otherwise. ### `gamepad_get_device_count()` **Description:** Returns the number of currently connected gamepad devices. **Method:** `gamepad_get_device_count() **Returns:** Integer representing the number of connected gamepad devices. ### `gamepad_enumerate()` **Description:** Returns a map of all currently connected gamepads, with device index as keys and their descriptions as values. **Method:** `gamepad_enumerate() **Returns:** A `Map` where keys are device indices (integers) and values are gamepad descriptions (strings). ``` -------------------------------- ### Get Tags of the Current Object (GML) Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Asset_Management/Assets_And_Tags/asset_get_tags Retrieves all tags assigned to the object from which the current instance was created. This example demonstrates a common use case by first getting the object's name and then its tags. ```gml var _current_object_name = object_get_name(object_index); var _my_tags = asset_get_tags(_current_object_name); if (array_length(_my_tags) > 0) { for (var i = 0; i < array_length(_my_tags); i++) { show_debug_message("My object tag: " + _my_tags[i]); } } else { show_debug_message("This object has no tags."); } ``` -------------------------------- ### wallpaper_set_subscriptions Function Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Live_Wallpapers/wallpaper_set_subscriptions Function to configure which system metrics you want to subscribe to and receive updates for. Pass an array of metric names as strings to enable subscription to specific hardware monitors. ```APIDOC ## wallpaper_set_subscriptions Function ### Description Configures which system metrics will be monitored and delivered via the Wallpaper Subscription Data event. Only subscribed metrics will be included in the wallpaper_subscription_data struct. ### Method Function Call ### Syntax wallpaper_set_subscriptions(subscriptions); ### Parameters - **subscriptions** (Array) - Required - An array containing strings representing the metrics you want to subscribe to. Valid metric names include: "cpu", "gpu", "battery", "ram", "disk", "network", "audio" ### Returns N/A ### Request Example ```gml // Subscribe to CPU, GPU, and RAM metrics wallpaper_set_subscriptions(["cpu", "gpu", "ram"]); // Subscribe to all available metrics wallpaper_set_subscriptions(["cpu", "gpu", "battery", "ram", "disk", "network", "audio"]); // Subscribe only to audio metrics wallpaper_set_subscriptions(["audio"]); ``` ### Usage Notes - Call this function before or after creating subscriptions as needed - Only metrics included in the subscriptions array will generate data in the Wallpaper Subscription Data event - Update frequency is approximately once per second for most metrics, except audio which updates ten times per second - Use `struct_exists()` to safely check for metric availability in the received data ``` -------------------------------- ### Example of draw_line_colour Usage (GML) Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Drawing/Basic_Forms/draw_line_colour This example demonstrates how to use the draw_line_colour function to draw a horizontal line with a color gradient from red at the starting point to blue at the ending point. Coordinates and colors are explicitly defined. ```gml draw_line_colour(50, 50, 300, 50, c_red, c_blue); ``` -------------------------------- ### Complete Sequence Creation with Graphic Track and Keyframes Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Asset_Management/Sequences/sequence_keyframe_new Demonstrates creating a complete sequence with a graphic asset track, including keyframe setup and keyframe data assignment. This example shows the full workflow of creating a sequence, adding a track, creating keyframes, populating keyframe data, and assigning the track to the sequence. ```gml myseq = sequence_create(); var mytracks = array_create(1); mytracks[0] = sequence_track_new(seqtracktype_graphic); var graphickeys = array_create(1); graphickeys[0] = sequence_keyframe_new(seqtracktype_graphic); graphickeys[0].frame = 0; graphickeys[0].length = 1; graphickeys[0].stretch = true; graphickeys[0].disabled = false; var graphickeydata = array_create(1); graphickeydata[0] = sequence_keyframedata_new(seqtracktype_graphic); graphickeydata[0].spriteIndex = spr_Platform; graphickeydata[0].channel = 0; graphickeys[0].channels = graphickeydata; mytracks[0].name = "TestGraphicTrack"; mytracks[0].keyframes = graphickeys; myseq.tracks = mytracks; ``` -------------------------------- ### Check and Reset Sound Track Position - GameMaker Language Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Asset_Management/Audio/audio_sound_get_track_position Example demonstrating how to check if a sound's track position is not at the start (0 seconds), and if so, reset it to the beginning using audio_sound_set_track_position. Useful for ensuring sounds start from the beginning of playback. ```gml if audio_sound_get_track_position(global.Music) != 0 { audio_sound_set_track_position(global.Music, 0); } ``` -------------------------------- ### mp_grid_path - Complete enemy pathfinding example in GameMaker Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Movement_And_Collisions/Motion_Planning/mp_grid_path Demonstrates practical implementation of mp_grid_path for enemy AI. Creates an MP grid, adds wall obstacles, generates paths for all enemy instances to navigate toward the player, and initiates path following. Shows the full workflow from grid creation through path execution with error handling via boolean return value. ```gml global.grid = mp_grid_create(0, 0, room_width div 32, room_height div 32, 32, 32); mp_grid_add_instances(global.grid, obj_wall, false); with (obj_enemy) { path = path_add(); if (mp_grid_path(global.grid, path, x, y, obj_player.x, obj_player.y, 1)) { path_start(path, 0, 3, 0); } } ``` -------------------------------- ### Check and Destroy Tilemap with Validation - GameMaker Language Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Asset_Management/Rooms/Tile_Map_Layers/layer_tilemap_destroy Complete example demonstrating how to get a layer ID, retrieve its associated tile map ID, verify the tile map exists, and then destroy it. Uses layer_get_id to get the layer, layer_tilemap_get_id to get the tile map ID, layer_tilemap_exists to validate existence, and layer_tilemap_destroy to remove it. ```gml var lay_id = layer_get_id("Tiles_trees"); var tile_id = layer_tilemap_get_id(lay_id); if (layer_tilemap_exists(lay_id, tile_id)) { layer_tilemap_destroy(tile_id); } ``` -------------------------------- ### Particle System Setup with Disabled Emitter - GameMaker Language Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Drawing/Particles/Particle_Emitters/part_emitter_enable Complete example demonstrating particle system initialization with two emitters, where one is disabled using part_emitter_enable. Shows creation of particle system, emitters, configuration with regions and distribution, and cleanup of dynamic resources. ```gml // Create Event ps = part_system_create(); pe1 = part_emitter_create(ps); part_emitter_region(ps, pe1, 100, 200, 100, 200, ps_shape_rectangle, ps_distr_gaussian); part_emitter_enable(ps, pe1, false); pe2 = part_emitter_create(ps); part_emitter_region(ps, pe2, 200, 300, 100, 200, ps_shape_rectangle, ps_distr_gaussian); pt = part_type_create(); part_type_speed(pt, 2, 2, 0, 0); part_type_direction(pt, 90, 90, 0, .2); part_emitter_stream(ps, pe1, pt, 2); part_emitter_stream(ps, pe2, pt, 2); // Cleanup Event part_emitter_destroy(ps, pe1); part_emitter_destroy(ps, pe2); part_system_destroy(ps); part_type_destroy(pt); ``` -------------------------------- ### Get Loop Start Point - GameMaker Language Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Asset_Management/Audio/Audio_Loop_Points/audio_sound_get_loop_start Retrieves the loop start point in seconds for a specified sound asset or sound instance. This function accepts either a sound asset ID or a sound instance ID as input and returns a Real value representing the start time in seconds. Useful for audio manipulation and playback control in GameMaker projects. ```gml audio_sound_get_loop_start(index); ``` ```gml var _loop_start_time = audio_sound_get_loop_start(snd_loop); ``` -------------------------------- ### buffer_set_surface - Create and Copy Surface Data Example Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Buffers/buffer_set_surface Complete example demonstrating surface creation, clearing, and copying buffer data into the surface using buffer_set_surface. Includes existence checks for both surface and buffer before performing the copy operation. Assumes buffer and surface use the same format (surface_rgba8unorm). ```gml if (!surface_exists(surf1)) { surf1 = surface_create(200, 200); surface_set_target(surf1); draw_clear_alpha(c_white, 0); surface_reset_target(); if (buffer_exists(buff1)) { buffer_set_surface(buff1, surf1, 0); } } ``` -------------------------------- ### Check and Toggle Background Stretch - GML Example Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Asset_Management/Rooms/Background_Layers/layer_background_get_stretch Practical example demonstrating how to get the layer handle, retrieve the background element ID, check if it is stretched, and conditionally disable stretching. This pattern is useful for managing background display properties dynamically during runtime. ```gml var lay_id = layer_get_id("Background_sky"); var back_id = layer_background_get_id(lay_id); if (layer_background_get_stretch(back_id)) { layer_background_stretch(back_id, false); } ``` -------------------------------- ### Start Instance Following a Path - GML Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Asset_Management/Paths/path_start Initiates an instance's movement along a specified path. Requires a path asset, movement speed, an end action constant, and a boolean for absolute/relative positioning. The instance's path index is stored in 'path_index'. Must be called from an instance's scope. ```gml path_start(path, 4, path_action_reverse, false); ``` -------------------------------- ### Get Object Name as String (GML) Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Asset_Management/Objects/object_get_name This GML code snippet demonstrates how to get the string name of an object using its index. The function returns a string, which can be further processed, for example, to retrieve the object's index using `asset_get_index()`. ```gml str = object_get_name(object_index); ``` -------------------------------- ### Gamepad Start Button Press Handler - GML Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Game_Input/GamePad_Input/gamepad_button_check_pressed Practical example that detects when the start button is pressed on gamepad device 0, plays a sound effect, and transitions to the Level_1 room. Demonstrates single-trigger behavior where the room change only occurs once per button press. ```gml if (gamepad_button_check_pressed(0, gp_start)) { audio_play_sound(snd_Start, 0, false); room_goto(rm_Level_1); } ``` -------------------------------- ### GML: Subscribe to Wallpaper Events and Log CPU Usage Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Live_Wallpapers/wallpaper_set_subscriptions This GML code snippet demonstrates subscribing to 'desktop_mouse' and 'cpu' events in the Create event. It then accesses the CPU subscription data in the Wallpaper Subscription Data event to log the current datetime, CPU count, and individual CPU usage percentages to a text file named 'sysinfo.txt'. ```gml // Create Event wallpaper_set_subscriptions(["desktop_mouse", "cpu"]); // Wallpaper Subscription Data Event var _cpus = wallpaper_subscription_data.cpu; file = file_text_open_append("sysinfo.txt"); file_text_writeln(file); file_text_write_string(file, string(date_current_datetime())); file_text_write_string(file, $"\nCPU count: {array_length(_cpus)}"); array_foreach(_cpus, function(_cpu, _num) { if (!struct_exists(_cpu, "usage_pct")) return; var _str = $"\nCPU {_num} load: {_cpu.usage_pct}%"; file_text_write_string(file, _str); }); file_text_close(file); ``` -------------------------------- ### Multi-Touch Input Overview Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Game_Input/Device_Input/Device_Input General overview of multi-touch input handling, platform limitations, and important considerations for cross-platform game development. ```APIDOC ## Multi-Touch Input Overview ### Description GameMaker device input functions support multi-touch input on platforms that permit it. Touch input works similarly to multi-mouse input on PC platforms. ### Touch Index Parameter All device input functions accept a "touch" parameter (touch_index) that corresponds to a specific touch on the device display: - **touch_index 0** - Primary/first touch - **touch_index 1+** - Additional simultaneous touches ### Platform Touch Limitations The maximum number of simultaneous touches varies by device and OS: - **Low-end Android devices** - May detect only 2-3 simultaneous touches - **Windows devices** - May detect up to 10 simultaneous touches - **Other platforms** - Varies based on hardware and OS capabilities ### Double-Tap Behavior - On touchscreen devices, a double tap is reported as a **right mouse button event** (`mb_right`) - To detect multiple taps in quick succession, check for both `mb_left` and `mb_right` - Double-click behavior can be toggled using `device_mouse_dbclick_enable()` ### Mobile Back Button - On Android, iOS, and Windows Phone, the back button is mapped to the `vk_backspace` keyboard constant - Detect back button presses using standard keyboard input functions checking for `vk_backspace` ### Mouse Coordinate Updates - Mouse coordinates are updated every frame - **Note on macOS**: Uses event handlers for mouse position capture, which may result in frames where the mouse moved but the position appears unchanged - Depending on platform, you may encounter frames where mouse coordinates are identical to the previous frame ``` -------------------------------- ### GML: Basic Physics Raycast Setup and Usage Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Physics/physics_raycast Sets up a physics world, creates edge-shaped fixtures, casts a ray, and draws debug information. This example demonstrates the fundamental use of `physics_raycast` for collision detection in a 2D physics environment. It requires `physics_world_create` and `physics_fixture_create` for setup. ```gml /// Create Event physics_world_create(0.1); fixtures = []; var _fix = physics_fixture_create(); physics_fixture_set_density(_fix, 0); repeat(100) { var _angle = random(360); var _x = random(room_width), _y = random(room_height); physics_fixture_set_edge_shape(_fix, _x, _y, _x + lengthdir_x(40, _angle), _y + lengthdir_y(40, _angle)); var _fix_bound = physics_fixture_bind(_fix, id); array_push(fixtures, _fix_bound); } physics_fixture_delete(_fix); x1 = room_width / 2; y1 = room_height / 2; x2 = mouse_x; y2 = mouse_y; hits = undefined; /// Step Event x2 = mouse_x; y2 = mouse_y; hits = physics_raycast(x1, y1, x2, y2, id, true); /// Draw Event physics_world_draw_debug(phy_debug_render_shapes); draw_line_colour(x1, y1, x2, y2, c_red, c_blue); if (is_undefined(hits)) { exit; } for(var i = 0; i < array_length(hits); i++) { var _hit = hits[i]; draw_line(_hit.hitpointX, _hit.hitpointY, _hit.hitpointX + _hit.normalX * 40, _hit.hitpointY + _hit.normalY * 40); } /// Clean Up Event for(var i = 0; i < array_length(fixtures); i++) { physics_remove_fixture(id, fixtures[i]); } ``` -------------------------------- ### video_open - Load Included Video File Example Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Drawing/Videos/video_open Demonstrates loading a video file (splash.mp4) from the project's Included Files directory. This is the basic usage pattern for loading local video resources packaged with the game. ```gml video_open("splash.mp4"); ``` -------------------------------- ### Conditional Object Persistence Setup Example Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Asset_Management/Objects/object_set_persistent Practical example demonstrating how to conditionally set object persistence based on the current room, then create an instance with the updated persistence setting. Checks if the current room matches a target room before modifying the object's persistent flag. ```gml if (room == rm_final) { object_set_persistent(obj_Player, false); } instance_create_layer(32, 32, "Instances", obj_Player); ``` -------------------------------- ### Get Particle System Asset from Layer Element - GML Example Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Asset_Management/Rooms/Particle_System_Layers/layer_particle_get_system Demonstrates retrieving a particle element ID from a layer and then obtaining its associated particle system asset. First gets the element ID using layer_particle_get_id, then retrieves the asset using layer_particle_get_system and stores it in a variable for further use. ```gml var _element_id = layer_particle_get_id("Effects", "particle_fire"); var _ps_asset = layer_particle_get_system(_element_id); ``` -------------------------------- ### audio_start_sync_group - Start Audio Sync Group Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Asset_Management/Audio/Audio_Synchronisation/audio_start_sync_group Starts playing a previously created sync group containing multiple audio tracks. Requires a valid group index obtained from audio_create_sync_group(). This functionality is not supported on HTML5 target platforms. ```APIDOC ## audio_start_sync_group ### Description Starts playing a previously created sync group. A sync group allows multiple audio tracks to be played together in synchronization. ### Syntax ``` audio_start_sync_group(group_index); ``` ### Parameters #### Arguments - **group_index** (Audio Sync Group ID) - Required - The group index to play. This value is returned when creating the group using audio_create_sync_group(). ### Returns N/A ### Platform Support **NOTE:** This functionality is not available for the HTML5 target platform. ### Request Example ```gml sg = audio_create_sync_group(true); audio_play_in_sync_group(sg, sound1); audio_play_in_sync_group(sg, sound2); audio_sound_gain(sound2, 0, 0); audio_play_in_sync_group(sg, sound3); audio_sound_gain(sound3, 0, 0); audio_play_in_sync_group(sg, sound4); audio_sound_gain(sound4, 0, 0); audio_start_sync_group(sg); ``` ### Response Example The above code creates a new sync group and assigns the index to the variable "sg". Four sounds are then added to the group, with the gain for three of them set to 0 (muted). Finally the sync group is started for playback. ``` -------------------------------- ### Host Webpage iframe Setup with Message Listener - HTML/JavaScript Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Cameras_And_Display/The_Game_Window/window_post_message HTML and JavaScript code for the host webpage that embeds the game in an iframe and establishes bidirectional communication. Includes an iframe element with sandbox restrictions, a button to send messages to the game, and an event listener to receive messages from the game runner. ```html ``` -------------------------------- ### Get layer background ID and change sprite in GameMaker Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Asset_Management/Rooms/Background_Layers/layer_background_get_id This example demonstrates getting a layer handle by name, retrieving the background element ID from that layer, and then using that ID to change the background sprite. It shows a practical workflow for manipulating background elements at runtime. ```gml var lay_id = layer_get_id("Background_trees"); var back_id = layer_background_get_id(lay_id); layer_background_sprite(back_id, bck_Trees_Winter); ``` -------------------------------- ### Clear Animation Track with Reset to Setup Pose - GameMaker Language Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Asset_Management/Sprites/Skeletal_Animation/Animation/skeleton_animation_clear Clears animation track 1 and resets the skeleton to its setup pose over 1 second. This example demonstrates using the optional reset and duration parameters to smoothly transition the skeleton back to its default pose after clearing animations. ```gml skeleton_animation_clear(1, true, 1); ``` -------------------------------- ### Initialize Particle System and Add Emitter in GameMaker Language Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Drawing/Particles/Particle_Emitters/part_emitter_create This example illustrates the process of creating a particle system instance from an asset, adding an additional emitter to it, defining the emission region, and setting up a continuous stream of particles. This showcases a more complex setup involving multiple GML functions. ```gml ps = part_system_create(ps_effects); pe = part_emitter_create(ps); part_emitter_region(ps, pe, 0, 100, 0, 100, ps_shape_ellipse, ps_distr_gaussian); part_emitter_stream(ps, pe, pt_smoke, 2); ``` -------------------------------- ### Call gxc_file_sync with Callback Method Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/GXC/File_System/gxc_file_sync Demonstrates how to use gxc_file_sync to synchronize file system changes with a callback function. The function is asynchronous and calls the provided callback method when synchronization completes. This example shows the complete implementation including the callback definition, initial setup in the Create event, and repeated calls in the Alarm event. ```gml confirm = function() { show_debug_message("Successfully synced file system changes!"); } alarm_time = 60; alarm[0] = alarm_time; gxc_file_sync(confirm); alarm[0] = alarm_time; ``` -------------------------------- ### Get Audio Recorder Count and Start Recording (GML) Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Asset_Management/Audio/Audio_Buffers/audio_get_recorder_count This GML code snippet checks the number of available audio recording devices. If at least one device is found, it proceeds to start recording from the first available device (index 0). This function is useful for games that utilize microphone input. ```gml if (audio_get_recorder_count() > 0 ) { channel_index = audio_start_recording(0); } ``` -------------------------------- ### Get Static Struct of a Function - GML Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Variable_Functions/static_get This example demonstrates how to retrieve the static struct of a function and access its static variables. It creates a `counter` function with a static `count` variable, calls it multiple times, then uses `static_get` to get the static struct. Finally, it shows that accessing `counter.count` and `_static_counter.count` yields the same result. ```gml function counter() { static count = 0; return count ++; } repeat (10) counter() // Get static struct of counter() var _static_counter = static_get(counter); // Both of these read the same variable show_debug_message(counter.count); // 10 show_debug_message(_static_counter.count); // 10 ``` -------------------------------- ### Gamepad Functions - Info & Config Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Game_Input/GamePad_Input/Gamepad_Input Functions for retrieving detailed information about connected gamepads and configuring their behavior. ```APIDOC ## Gamepad Info & Configuration Functions These functions allow you to retrieve specific details about connected gamepads and adjust their settings. ### `gamepad_get_guid(device_index)` **Description:** Retrieves the GUID (Globally Unique Identifier) of a gamepad device. **Method:** `gamepad_get_guid(device_index) **Parameters:** - **device_index** (integer) - The index of the gamepad device. **Returns:** String representing the gamepad's GUID. ### `gamepad_get_description(device_index)` **Description:** Retrieves a descriptive name for the gamepad device. **Method:** `gamepad_get_description(device_index) **Parameters:** - **device_index** (integer) - The index of the gamepad device. **Returns:** String describing the gamepad. ### `gamepad_get_button_threshold(device_index)` **Description:** Gets the current button threshold for detecting presses. **Method:** `gamepad_get_button_threshold(device_index) **Parameters:** - **device_index** (integer) - The index of the gamepad device. **Returns:** Float representing the button threshold (0.0 to 1.0). ### `gamepad_get_axis_deadzone(device_index)` **Description:** Gets the current axis deadzone value. **Method:** `gamepad_get_axis_deadzone(device_index) **Parameters:** - **device_index** (integer) - The index of the gamepad device. **Returns:** Float representing the axis deadzone (0.0 to 1.0). ### `gamepad_get_option(device_index, option)` **Description:** Retrieves the value of a specific gamepad option. **Method:** `gamepad_get_option(device_index, option) **Parameters:** - **device_index** (integer) - The index of the gamepad device. - **option** (enum `gamepad_options`) - The gamepad option to retrieve. **Returns:** The value of the specified option. ### `gamepad_set_button_threshold(device_index, threshold)` **Description:** Sets the button threshold for detecting presses. **Method:** `gamepad_set_button_threshold(device_index, threshold) **Parameters:** - **device_index** (integer) - The index of the gamepad device. - **threshold** (float) - The new button threshold (0.0 to 1.0). ### `gamepad_set_axis_deadzone(device_index, deadzone)` **Description:** Sets the deadzone for analog axes. **Method:** `gamepad_set_axis_deadzone(device_index, deadzone) **Parameters:** - **device_index** (integer) - The index of the gamepad device. - **deadzone** (float) - The new axis deadzone (0.0 to 1.0). ### `gamepad_set_vibration(device_index, left_motor, right_motor)` **Description:** Sets the vibration motor speeds for a gamepad. **Method:** `gamepad_set_vibration(device_index, left_motor, right_motor) **Parameters:** - **device_index** (integer) - The index of the gamepad device. - **left_motor** (float) - Speed for the left motor (0.0 to 1.0). - **right_motor** (float) - Speed for the right motor (0.0 to 1.0). ### `gamepad_set_colour(device_index, colour)` **Description:** Sets the LED color for compatible gamepads. **Method:** `gamepad_set_colour(device_index, colour) **Parameters:** - **device_index** (integer) - The index of the gamepad device. - **colour** (integer/color) - The color to set (e.g., `c_red`, `colour`). ### `gamepad_set_option(device_index, option, value)` **Description:** Sets the value of a specific gamepad option. **Method:** `gamepad_set_option(device_index, option, value) **Parameters:** - **device_index** (integer) - The index of the gamepad device. - **option** (enum `gamepad_options`) - The gamepad option to set. - **value** (variant) - The value to set for the option. ### `gamepad_axis_count(device_index)` **Description:** Returns the number of analog axes available on the gamepad. **Method:** `gamepad_axis_count(device_index) **Parameters:** - **device_index** (integer) - The index of the gamepad device. **Returns:** Integer representing the number of axes. ### `gamepad_button_count(device_index)` **Description:** Returns the number of buttons available on the gamepad. **Method:** `gamepad_button_count(device_index) **Parameters:** - **device_index** (integer) - The index of the gamepad device. **Returns:** Integer representing the number of buttons. ### `gamepad_hat_count(device_index)` **Description:** Returns the number of hat switches (D-pads) available on the gamepad. **Method:** `gamepad_hat_count(device_index) **Parameters:** - **device_index** (integer) - The index of the gamepad device. **Returns:** Integer representing the number of hat switches. ``` -------------------------------- ### Initialize Custom Primitive with vertex_begin in GML Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Drawing/Primitives/vertex_begin This example demonstrates how to define a vertex format, create a vertex buffer, and start defining a custom primitive using vertex_begin. The function prepares the buffer for vertex data input with a specified format that includes position, color, and texture coordinates. ```gml vertex_format_begin(); vertex_format_add_position(); vertex_format_add_colour(); vertex_format_add_texcoord(); v_format = vertex_format_end(); v_buff = vertex_create_buffer(); vertex_begin(v_buff, v_format); ``` -------------------------------- ### Reset and Start Time Source with GML Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Time_Sources/time_source_reset This example demonstrates how to reset a Time Source using `time_source_reset` and then immediately restart it using `time_source_start`. This is typically done in an event like 'Room Start' to ensure a fresh countdown when a new room begins. It takes a Time Source ID as an argument. ```gml // Room Start event time_source_reset(global.spawn_time_source); time_source_start(global.spawn_time_source); ``` -------------------------------- ### Get and Offset Tile Map Position - GML Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Asset_Management/Rooms/Tile_Map_Layers/tilemap_get_x Retrieves both x and y positions of a tile map element and then offsets them by 10 pixels. This example demonstrates retrieving the layer ID, getting the tile map ID from that layer, obtaining both coordinates, and applying position changes using tilemap_x() and tilemap_y() functions. ```gml var lay_id = layer_get_id("Tiles_Walls"); var map_id = layer_tilemap_get_id(lay_id); var _x = tilemap_get_x(map_id); var _y = tilemap_get_y(map_id); tilemap_x(map_id, _x + 10); tilemap_y(map_id, _y + 10); ``` -------------------------------- ### Create and Save GIF from Application Surface Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Cameras_And_Display/gif_add_surface Complete example demonstrating GIF creation workflow: initializes a GIF on first frame, adds 29 frames from the application surface with 6/100th second delays, and saves the final GIF file. Shows typical pattern for capturing game frames into an animated GIF. ```gml if (save_gif == true) { if (count == 0) { gif_image = gif_open(room_width, room_height); } else if (count < 30) { gif_add_surface(gif_image, application_surface, 6/100); } else { gif_save(gif_image, "GameCapture.gif"); count = 0; save_gif = false; } count++; } ``` -------------------------------- ### tile_set_index - Complete tilemap manipulation example Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Asset_Management/Rooms/Tile_Map_Layers/tile_set_index Demonstrates a complete workflow for modifying tilemap tiles at the mouse position. The example retrieves the tilemap ID from a layer, gets the tile-data at the current mouse coordinates, changes the tile index to a random value, and applies the modified data back to the tilemap using tilemap_set(). ```gml var lay_id = layer_get_id("Tiles_sky"); var map_id = layer_tilemap_get_id(lay_id); var mx = tilemap_get_cell_x_at_pixel(map_id, mouse_x, mouse_y); var my = tilemap_get_cell_y_at_pixel(map_id, mouse_x, mouse_y); var data = tilemap_get(map_id, mx, my); var ind = tile_get_index(data); data = tile_set_index(data, irandom(23)); tilemap_set(map_id, data, mx, my); ``` -------------------------------- ### Start Audio Sync Group Playback - GML Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Asset_Management/Audio/Audio_Synchronisation/audio_start_sync_group Initiates playback of a previously created sync group by providing its group index. The sync group must have been created using audio_create_sync_group() and configured with audio_play_in_sync_group() before calling this function. This function has no return value and is unavailable for HTML5 targets. ```gml audio_start_sync_group(group_index); ``` -------------------------------- ### Get Struct Variable Count in GML Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Variable_Functions/variable_struct_names_count This GML code snippet demonstrates how to use the struct_names_count function to get the number of variables in a struct. It takes a struct ID as input and returns an integer representing the variable count. If the struct does not exist, it returns -1. The example shows how to store the result and display it in the debug output. ```gml var _num = struct_names_count(mystruct); show_debug_message("Struct Variables = " + string(_num)); ``` -------------------------------- ### Start Time Source (GML) Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Time_Sources/time_source_start This GML code demonstrates how to start a Time Source. It includes creating a method for a callback, initializing a Time Source with specific parameters (period, units, callback method), and finally starting the Time Source. The Time Source is configured to trigger the callback after a set number of frames. ```gml var _my_method = function() { instance_destroy(); } var _time_source = time_source_create(time_source_game, 300, time_source_units_frames, _my_method); time_source_start(_time_source); ``` -------------------------------- ### Get GUI Height and Draw Bottom-Aligned Text in GML Source: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/Cameras_And_Display/display_get_gui_height Retrieves the GUI height using display_get_gui_height() and uses it to position text at the bottom-left corner of the GUI. This example demonstrates getting the current vertical text alignment, changing it to bottom-aligned, drawing text, and restoring the original alignment. Call this in a Draw GUI event for accurate results. ```gml var _height = display_get_gui_height(); var _valign = draw_get_valign(); draw_set_valign(fa_bottom); draw_text(5, _height - 5, "I am drawn in the bottom-left corner of the GUI"); draw_set_valign(_valign); ```