Animation - Grisgram/gml-raptor GitHub Wiki

The Animation class is a powerful tool that will feel like a Sequence when you use it, but it is not. It's more than that (and less, at the same time). What I tried to achieve with Animations is to have a quick way of modifying one or more properties (built-ins, like x, y, speed, angle, alpha,... etc) over time without having to create a sequence asset for each of those and without doing by-frame calculations in the step event of each object.
This would only lead to messy code that is not reusable and almost impossible to maintain efficiently.

Animation vs. Sequence

While sequences are ok as an idea in GameMaker (not great, but ok), they still struggle with lots of bugs that made them almost unusable for me. So I turned away from them except to make static cutscenes or simple UI animations like sliding buttons and other things like that. They are ok for that, but in my opinion they are the wrong tool for any kind of dynamic movement which will interact with the current scene in any way.

The biggest flaws in sequences:

  • They create their own instances when started and we have to use sequence_instance_override_object to replace the object from the sequence with one in the scene. With one. What if a sequence shall move a pair or a group of objects? Will it replace one of them at random? The first one? The last one? This is not reliable or in any form maintainable. It's a mixture of designer-work and coding in no particular order. So... great for static cutscenes, but that's it.
  • Sequences are independent from the scene, but at the same time they are so invariable when it comes to move distance or any dynamically changing values. More or less you are forced to create multiple sequences for the same thing just because they move a bit further or faster or rotate a bit more or less. It's a conceptual and architectural problem that sequences have. Again, for static cutscenes they're ok, but the usability almost ends there.

Sequences basically interpolate AnimCurves on objects over time. When we look closer at the AnimCurve feature of GameMaker, we quickly discover that they are a super powerful tool to interpolate (animate...) any value over time.
The best thing on AnimCurves is that they can contain multiple channels (curves) in a single AnimCurve asset.

This is what the Animation class uses in a super-easy and intuitive way that requires no further coding. You may add code to Animations, you can register callbacks (they are called Triggers in the Animation), but you don't have to. But if you do, your code is all in one place which makes any Animation easy to maintain.

Animation and AnimCurves

When starting/creating an Animation, you must supply

  • The object to animate (who gets animated) - this is the owner of the Animation.
  • A delay (when shall it start from now).
  • A frame count (how long shall it last).
  • An AnimCurve (what in the object is animated).
  • The number of repeats. (Default = 1, setting this to -1 means "infinite")

This AnimCurve is what makes the Animation class so powerful.
As I mentioned above, one single AnimCurve asset can have multiple channels in it. And each channel has a name. So I thought, "What if the NAME of the channel represents the property to animate?". And this was the solution I used to build this class.


As the Animation is quite a powerful class, there's more to tell than a simple list of functions.
Read on in

Using AnimCurves How to use curves for animations
Animation meets StateMachine How they work together
Animation Triggers What triggers exist and how do they work?
Animation Chaining Connect and loop animations to form sequences
Animation Functions (Class) A complete list of Animation functions
Animation Functions (Global) A complete list of Animation support functions
abort() vs finish() How to end an Animation early
⚠️ **GitHub.com Fallback** ⚠️