Animation struct and variables - KormexGit/GM-Animate GitHub Wiki
animation_start (or animation_get, after animation_start has been called) will return the struct of data used for an animation. This struct contains all of that animation's variables as well as some private methods.
The following variables are the same as GM built ins, in both name and functionality:
- image_index
- image_speed
- image_xscale
- image_yscale
- image_angle
- image_blend
- image_alpha
Note
x and y are not present in the struct. The position of the animation is set in the arguments for animation_draw.
There are three main ways to access the animation struct to edit it's variables:
- Store it the return of animation_start in a variable.
- Retrieve it using animation_get.
- Access the
animations
array on the object directly. This array is created when animation_start is called for the first time. Each index in the array contains the animation struct for the corresponding track.
Example of changing variables, with all three methods of accessing the animation struct:
//Create event
animation_start(spr_idle, true, 0);
animation_start(spr_weapon, true, 1);
//Step event
if hsp != 0 {
animation_change(spr_walk);
var anim_main = animation_get();
anim_main.image_xscale = sign(hsp);
}
if shoot {
var muzzle_flash = animation_start(spr_muzzle_flash, false, 2);
muzzle_flash.image_angle = animations[1].image_angle; //animations[1] is the the animation struct for spr_weapon, which was started in the create event
}
For actual code you most likely want to pick one way of accessing the struct and stick to it, rather than using all 3 ways at the same time.
Important
image_xscale, image_yscale, and image_angle will not affect the object's collision mask unless you use animation_set_instance_mask.
sprite_index is present in the animation struct, but changing it directly will not update the frame rate of the animation to the new sprite, so it is not recommended to edit it directly. Instead, animation_start can be called again to swap to a different animation, but this creates a new animation struct and thus will reset any active effects, the animation queue, and changes you made to editable variables. Use animation_change instead if you want to change which sprite is used without creating a new struct and resetting things.
- loop
- boolean, determines if the animation loops or not. Can also be accessed with animation_get_looping and animation_set_looping.
Note
If loop is set to false, the animation's image_speed will be set to 0 when it finishes. If animation_change is called after, then image_speed will be set back to 1.
- paused
- boolean, pausing will stop the animation and any active effects from progressing. Can also be accessed with animation_get_pause, animation_set_pause, and animation_set_pause_all.
Note
Pausing is different from the hitstop effect. Pausing will pause everything, including effects, while hitstop only stops the animation itself and effects will continue to update.