Studio › Manual › State machines

State machines in the game (GML)

Export to Game (⌃⇧⌘.) writes two scripts into an "Anim Machines" folder: anim_machine_runtime (the runtime) and anim_machines_data (every machine, as GML text, so the game reads no files and runs on every platform). The .animmachine file stays an included file: it is the machine's source, kept with the project. Export again after changing a machine. The usage code goes on the clipboard:

// Create
skel = skel_create("hero"); // Bones (or: machine = anim_machine_create("box", id) for a sprite)
machine = anim_machine_create("hero", skel);
// Step
anim_set_param(machine, "speed", abs(hsp));
anim_set_param(machine, "grounded", on_ground);
if (keyboard_check_pressed(vk_space)) anim_trigger(machine, "jump");
anim_machine_step(machine, delta_time / 1000000);
skel_update(skel, delta_time / 1000000);

Queries: anim_state, anim_state_time, anim_state_normalized, anim_in_transition, anim_prev_state, anim_clips (clip, time, weight), anim_main_clip, anim_get_param, anim_events (enter, exit, transition, end), anim_entered(machine, "Jump"), machine.on_event = function(type, state, from, to) {}; anim_machine_play(machine, state, fade) jumps to a state.

What it plays on (the machine's inspector): a Bones skeleton (its tracks from the first track you choose, the layers' after them; export Bones first), Sprites (sprite_index and image_index of the instance, a clip being a sprite or a run of its frames at a speed), a 3D model of the Room 3D kit (an o_r3d_thing: the machine poses it, blending every clip playing, crossfades and blend spaces included, at the machine's own times and speeds, and its layers; the strongest clip also plays with r3d_play so anim, its events and attachments follow), or nothing (read anim_clips yourself). The runtime only holds the drivers the project has when you export, so it always builds.

Keys are shown as on the Mac: ⌘ Command, ⌥ Option, ⌃ Control, ⇧ Shift. Studio for Windows shows its own keys beside each menu item.