2D Animations for Game Entities with multiple animation loops


I wanted to discuss 2D animations here, specifically in the case of an entity like a character which has multiple, different animation loops. I would like to know how you guys go about implementing this in your games. I am not 100 percent confident with my solutions to this issue.

In the docs this is the code that shows how to load different Tiles into one Animation:
var t1 = h2d.Tile.fromColor(0xFF0000, 30, 30);
var t2 = h2d.Tile.fromColor(0x00FF00, 30, 40);
var t3 = h2d.Tile.fromColor(0x0000FF, 30, 50);
var anim = new h2d.Anim([t1, t2, t3], s2d);

So far so good, but now we just have one animation. What about a character for example, which can walk into different directions, has different walk animations for idling, running, jumping, shooting and so on. What are you doing in this case?

One possibility would be to initialise a map like this:
_animFrames = new Map<String, Array<h2d.Tile>>();
_animFrames["idle/down"] = [tiles[1][0]];
_animFrames["move/down"] = [tiles[0][0], tiles[1][0], tiles[2][0]];

And an empty animation like this:
_anim = new h2d.Anim(null, null, this);

And whenever that entity’s behaviour changes, then play the proper framed like this:

Another possibility would be to initialise several Anims first, put them all into a Map like this:
_anims = new Map<String, h2d.Anim>();

And just set the one to visible that is currently active.

Both of these solutions don’t strike me as very elegant. How are you guys going about this?


Regarding Heaps: Such feature considered “too advanced”, hence not present. I personally use my own animation container: https://github.com/Yanrishatum/heeps/blob/master/h2d/AnimationExt.hx
It provides me flexible animation control such as:

  • Events - binds to animation looping, commands and frames.
  • Precise control over how long each frame is shown
  • Personalized tinting options for each frame
  • Command sequencing via rudimentary command pipeline
  • Animation speed control (no reverse, however)
  • Obviously - named animations.

However initialization of said animations is up to you. You could use same methods you described, or use external animation information via resource pipeline or such.