GameMaker 2023.4 brings string templates, better sprite loading, new struct functions and more.
String Templates
This new feature makes it easier to build strings with variables.
Where you would previously have to do this:
value = 116.23;
text = “I am “ + string(value) + “ years old.”
Now, you only need this:
value = 116.23;
text = $”I am {value} years old.”
// Start your string with $ and write expression in {}
With this, build long and clean strings with expressions inserted into it:
Async Sprite Loading
You could always load sprites in the middle of your game, but it would freeze the game while it loaded each sprite.
Now, load sprites asynchronously with sprite_add_ext(). You can load PNG, JPEG, GIF, QOIF and Spine JSON files through this function.
sprite_request = sprite_add_ext(directory + “sprite.png”, 1, 0, 0, true);
Once your sprite has been loaded, the Async Image Loaded event is triggered, where you can confirm that the correct sprite was loaded:
loaded_sprite = async_load[? “id”];
if (sprite_request == loaded_sprite)
{
var _filename = async_load[? “filename”];
var _http_status = async_load[? “http_status”]; // 200 if loaded successfully
var _status = async_load[? “status”]; // >=0 if successful, otherwise error code
}
For the list of error codes, see the sprite_add_ext() page.
Glow And More Filters
This release adds five new filters/effects:
- Glow (Effect)
- Recursive Blur (Effect)
- Clouds (Filter)
- Blend (Single-layer only effect)
- Blend Ext (Single-layer only effect)
Blend and Blend Ext allow you to apply blend modes to a layer. These effects can only be applied to non-FX layers, as they function on one layer at a time.
New Struct Functions
Structin’ just got easier and faster.
Use struct_foreach() to run operations on each member of a struct. Give it a function, and let it cook:
var _inventory = { apples: 17, bananas: 261, oranges: 2, lemons: 5 };
struct_foreach(_inventory, function(_name, _value)
{
show_debug_message($"{_name}: {_value}");
});
// This will print:
// bananas: 261
// oranges: 2
// lemons: 5
// apples: 17
To make it faster to work with struct variables using strings, you can get a hash first, and then use the hash to read/write to the variable:
var _struct = {a: {aa:1000}, b: 88, c: 99};
var _hash = variable_get_hash("aa");
var _value = struct_get_from_hash(_struct.a, _hash);
struct_set_from_hash(_struct.a, _hash, _value + 100);
You can use self to access a hashed variable from the current instance.
All existing variable_struct_* functions now have struct_* versions for easier writing. The documentation prefers the new aliases, for example, the variable_struct_get_names() page is now called struct_get_names().
Get Particle System Info
The previous release saw the addition of a Particle Editor. However, you could not “explore” the system at runtime, to get the emitters and particle types used within it.
Well, now you can! Call particle_get_info() on a Particle System asset, and this gives you a detailed struct with its emitters and types:
For example, you can now get the particle type used in an emitter, and spawn it yourself using part_particles_create():
// Create event
part_info = particle_get_info(ParticleSystem1);
part_type = part_info.emitters[0].parttype.ind;
part_sys = part_system_create();
// Step event
part_particles_create(part_sys, mouse_x, mouse_y, part_type, 1);
The parttype struct in an emitter gives you all the properties of the particle type as well, so you can recreate it yourself.
Read the particle_get_info() page for more information.
Audio End Event
Any played sound will now trigger the new “Async - Audio Playback Ended” event when it ends.
This event will give you the following async_load map keys:
- “sound_id”: The ID of the sound instance that stopped playing
- “asset_id”: The ID of the sound asset
- “was_stopped”: This is true when the sound was manually stopped, or was forced to stop playing due to channel limitations; otherwise it’s false
More GML Updates
2023.4 brings some new GML changes:
- array_shift() removes the first item from an array and returns it
- variable_clone() lets you clone a struct/array structure
- Use lin_to_db() and db_to_lin() to convert linear gain to decibels, or vice-versa
- Use window_set_showborder() to enable/disable the window border on Windows
- array_copy(), array_delete() and array_insert() now support negative index and length values
- There are new compile time macros for debug purposes: _GMLINE_, _GMFILE_ and _GMFUNCTION_
Misc. Changes
- The Build menu now has options to re-run the project, and clean code, graphics and audio separately
- There is a new preference under General -> Paths to automatically clean up temporary files before each build, which saves disk space when repeatedly building large projects
- In the Sequence Editor, keyframes now move with the asset key; this can be changed in the preferences
Download GameMaker 2023.4 and start creating now.
Happy GameMaking!