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];
_animFrames["move/down"] = [tiles, tiles, tiles];
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?