Skip to content

Instantly share code, notes, and snippets.

//this requires camera 0 to be active in all rooms you wish to be auto scaled
#macro __SETTINGS_AUTO_SCALE true
//these settings will require Window's window resize setting to be set to true
#macro __SETTINGS_ALLOW_WINDOW_RESIZE_HORZ true
#macro __SETTINGS_ALLOW_WINDOW_RESIZE_VERT true
@tinkerer-red
tinkerer-red / Promise.gml
Last active April 24, 2024 19:43
Javescript Promises in GameMaker's GML
#macro PROMISE_MAX_TIME (1/60 * 1_000 * 1_000) * (1/16) //the max time in milli seconds to spend on the promises, default is 1/16 of frame time of a 60 fps game
enum PROMISE_STATE {
PENDING,
RESOLVED,
REJECTED,
PAUSED,
};
function __PromiseNamespace__() {
@tinkerer-red
tinkerer-red / scrCollisions.gml
Last active April 27, 2024 04:38
more collision functions
//feather ignore all
#region jsDoc
/// @func collision_circle_array()
/// @desc This function is the same as the collision_circle() function, only instead of just detecting one instance / tile map in collision at a time, it will detect multiple instances or tile maps.
/// @param {Real} x1 : The x coordinate of the center of the circle to check.
/// @param {Real} y1 : The y coordinate of the center of the circle to check.
/// @param {Real} rad : The radius (distance in pixels from its center to its edge).
/// @param {Id.TileMapElement | Asset.GMObject | Id.Instance | Constant.All | Constant.Other | Array} obj : Asset or Object Instance or Tile Map Element ID or Array An object, instance, tile map ID, keywords all/other, or array containing these items
/// @param {Bool} prec : Whether the check is based on precise collisions (true, which is slower) or its bounding box in general (false, faster).
@tinkerer-red
tinkerer-red / CollisionArray.gml
Last active November 16, 2023 15:15
GML Collision Array Functions
#region jsDoc
/// @func collision_circle_array()
/// @desc This function is the same as the collision_circle() function, only instead of just detecting one instance / tile map in collision at a time, it will detect multiple instances or tile maps.
/// @param {Real} x1 : The x coordinate of the center of the circle to check.
/// @param {Real} y1 : The y coordinate of the center of the circle to check.
/// @param {Real} rad : The radius (distance in pixels from its center to its edge).
/// @param {Object} obj : Asset or Object Instance or Tile Map Element ID or Array An object, instance, tile map ID, keywords all/other, or array containing these items
/// @param {Boolean} prec : Whether the check is based on precise collisions (true, which is slower) or its bounding box in general (false, faster).
/// @param {Boolean} notme : Whether the calling instance, if relevant, should be excluded (true) or not (false).
/// @param {Array} array : The array to use to store the IDs of colliding instances
@tinkerer-red
tinkerer-red / GMString.gml
Last active October 25, 2023 17:30
GMString
///feather ignore all
function GMString(_val_or_format, _arg1=undefined, _arg2=undefined, _arg3=undefined, _arg4=undefined, _arg5=undefined, _arg6=undefined, _arg7=undefined, _arg8=undefined, _arg9=undefined, _arg10=undefined, _arg11=undefined, _arg12=undefined, _arg13=undefined, _arg14=undefined, _arg15=undefined) : __GMString__() constructor{
str = string(_val_or_format, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8, _arg9, _arg10, _arg11, _arg12, _arg13, _arg14, _arg15);
length = string_length(str);
}
function GMStringExt(_val_or_format, _arg_array) : __GMString__() constructor{
str = string_ext(_val_or_format, _arg_array);
length = string_length(str);
}
function GMStringFormat(_val, _total, _dec) : __GMString__() constructor{
@tinkerer-red
tinkerer-red / string_split_by_width direct conversion.gml
Created October 19, 2023 12:44
GML : string_split_by_width()
function string_split_by_width(_str, _line_width, _font=draw_get_font()) {
if (_str == undefined) return;
if (_line_width < 0) _line_width = 10000000; // means nothing will "wrap"
var _prev_font = draw_get_font();
draw_set_font(_font);
var _whitespace = " ";
var _newline = chr(0x0a); // \n
@tinkerer-red
tinkerer-red / gist:388b323a9bd43a8555c8322cdf0f7187
Created October 12, 2023 16:06
GML implementation of `trace`
#macro trace __trace(_GMFILE_+"/"+_GMFUNCTION_+":"+string(_GMLINE_)+": ")
function __trace(_location) {
static __struct = {};
__struct.__location = _location;
return method(__struct, function(_str){
show_debug_message(__location + ": " + string(_str));
});
}
@tinkerer-red
tinkerer-red / super example.gml
Created October 12, 2023 10:25
Example of super using a self contained callstack
function log(_str) {return show_debug_message(_str)};
function A() constructor {
static example = function(){
log("Calling A");
}
}
function B() : A() constructor {
static example = function() {
@tinkerer-red
tinkerer-red / current_room_to_struct.gml
Created October 12, 2023 07:07
GML: Room to struct boiler plate code
function current_room_to_struct() {
var _room = {
"Controls" : {
//"room_goto" : room_goto(),
//"room_goto_next" : room_goto_next(),
//"room_goto_previous" : room_goto_previous(),
//"room_restart" : room_restart(),
},
"Room Settings" : {
@tinkerer-red
tinkerer-red / gist:30aa7efe7a1f42ba7d077ace3183fc22
Last active October 12, 2023 16:04
GML constructor `base` keyword
#macro base __base(_GMFUNCTION_);
function __base(_func_name) {
static __lookup = {};
if (struct_exists(__lookup, _func_name)){
return __lookup[$ _func_name];
}
//used to break out once we have found a reliable answer
repeat(1) {