So I was wondering if anyone had some advice on how they tied their animation system into other aspects of the game. Right now, I have a pretty simple Entity-Component design set up, with one of the Components being an AnimatedSpriteComponent. The ASC owns an AnimationManager, which essentially is a Dictionary of Animations with some code built around it to facilitate the timing, playing, and other aspects of animation.
So to get to my question, how do you tie your Animations into your other Systems? Right now, I have a MovementComponent that essentially holds the “physical” aspects of an entity (direction it’s facing, speed, position, states such as idle, walking, running, etc). This component is included on every entity by default, as I use it as a sort of “glue” compenent (i.e. the AnimatedSpriteComponent will get the position from this for drawing). Right now, the AnimatedSpriteComponent looks at it’s owner and decides what animation to play based on it’s current state. Is this a good way to go about this? Or am I walking into unforseen dangers? I’d love to decouple things as much as possible, but it seems like I have a pretty strong coupling here. However, I do think that game programming has a degree of coupling that is unavoidable.
So am I on the right track that the AnimatedSpriteComponent decides what animation to play? Or should other systems be telling it what to play? i.e.:
a) The input handler sees the player wants to swing their sword, so it tells the AnimatedSpriteComponent to play the “Swing Sword” animation
or
b) The input handler sees the player wants to swing their sword, so it updates the MovementComponent to put the player in a “SWING_SWORD” state. The AnimatedSpriteComponent will then later see the Entity is in the “SWING_SWORD” state, and then switch the sprite to the correct animation
Sorry if this is a bit wordy. I didn’t include any code since this is more of a code design quesiton, but I’d be happy to if it would help.
Thanks