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:
_anim.play(_animFrames["move/down"]);

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.

I ported over my own animation manager to essentially just cycle collections of tiles with playback rules. From what I gather this is what the OOB anim stuff does as well so i feel alright about it.

A bigger issue for me has been porting over my skeletal animation system for 2d characters, where each sprite that makes up the character is a potential animation target (eyes blinking, lipsync, hands closing/opening etc). I’m currently batching every involved sprite’s current frame (uvs in texture) into a mesh of quads but I’m not sure this is the best way to go about it.

I need to dig into Heaps more and understand tiles better. I’m currently more comfortable passing textures and uvs around than working with tiles because I’m not sure if Heaps performs any kind of render state sorting/batching based on which tile is rendered when, so I just handle that myself, and at that point I might as well just draw indexed with a texture anyway.

I would love to see some solid OOB Res convert support for tools like Spine to just close the book on this issue. I don’t think robust sprite sequence playback should be considered too advanced for a game engine: We’ll all just wind up making our own then, who wins?