Animation Triggers - Grisgram/gml-raptor GitHub Wiki

Triggers are an extremely useful feature of Animation. You can specify several points during the lifetime of a running Animation to execute actions such as playing a sound or changing state (as shown in the examples on the previous page). You can even synchronize multiple concurrent running Animations on different objects through triggers by setting or changing the state of other objects (like starting the "Hit" animation on an enemy when the "Strike" animation on a sword reaches frame X where the sword touches the enemy).

This is the list of available triggers in Animation:

Trigger Function Description
Started add_started_trigger(func) Invoked on the first frame of an Animation.
func receives 1 parameter: data.
Finished add_finished_trigger(func) Invoked on the last frame of an Animation.
func receives 1 parameter: data.
Frame add_frame_trigger(frame,func,interval) Invoked on a specified frame and if you set interval to true, then every x frames (The default for interval is false).
IMPORTANT: A trigger set up as interval will fire every x frames, independent of the animation length, if it is looping!
Example: Your animation runs 20 frames, 3 repeats and you set an interval trigger every 8 frames. Then the trigger will fire on frames 8, 16, 24, 32,... and so on. It does not reset when a loop is finished!
func receives 2 parameters: data, frame.
Loop add_loop_trigger(func) If the Animation has more than 1 repeats set, this gets invoked every time, one loop of the Animation is finished (= the last frame has been reached).
func receives 1 parameter: data.

...and again: The almighty data

You know that each Saveable object and each StateMachine own a data member to store any data in the instance you like.
The same is true for the Animation. It also contains a data member, and this member will be forwarded as first parameter to each Trigger callback so you can easily share data between the triggers.

Scoping of Triggers

Triggers are scoped to the owner, the game object holding the Animation in the same way as the state callbacks in a StateMachine are scoped to its owner.


Next to read: Animation Chaining

⚠️ **GitHub.com Fallback** ⚠️