I probably should’ve posted this before starting to code it, but better late than never I guess.
This is a discussion about how to implement the animation functionality, how it will work and how to use it. The animation discussed here is the type which controls properties of sprites/other objects at runtime, they aren’t spritesheet-animations.
I’m gonna start of by explaining the way I see it (and foolishly started working on already):
There is always only one animator class, a GameComponent bound to the game (updates when game updates…).
Animator play stored and non-stored animations, accessing them via name.
Animations will have a Layer (int) property, animations can be layered so there’s only one running animation per layer possible. Ex: (Layer 1: movement(walking, running) Layer 2: actions(shoot, open door).
They also hold events to invoke at certain times.
Animations contain AnimationTrackGroups which group AnimationTracks per transformable (the object being transformed). They can swap out the transformable at runtime for one of the same type (even while the animation is running)
AnimationTracks contain Transformations, grouped by type (basically a Row in any animator software) this to make sure values are only interpolated between members of the same type.
Transformations contain a time and a value. They can interpolate (tween) or just set the value at the desired time. These are different types (ITweenTransform, ISetTransform) tweening means it will interpolate the value and previous value based on time and previous time, there is an Easing class to change this interpolation.
they can be added to the animation directly (which will handle the track/trackgroup):
syntax: transformable, property, time, value
animation.AddTweenTransform(sprite, s => s.Position, 100, Vector2.One); animation.AddSetTransform(sprite, s => s.IsVisible, 0, true);
or they can be constructed and added to the animation:
var scaletransform1= new ScaleTransform<Sprite>(0, Vector2.One); var scaletransform2 = new ScaleTransform<Sprite>(100, Vector2.Zero); animation.AddTransformations(sprite, scaletransform1, scaletransform2 );
Transforms can be based on interfaces (such as IMoveable, IScalable…) or use reflection to select properties.