A manager for animations. The type variables for this type are the same as those for App.
This asynchronously manages a set of running animations, advancing each one over time. When a running animation's current frame needs to be changed, the manager sends an EventM update for that animation to the application's event loop to perform the update to the animation in the application state. The manager will batch such updates if more than one animation needs to be changed at a time.
The manager has a tick duration in milliseconds which is the resolution at which animations are checked to see if they should be updated. Animations also have their own frame duration in milliseconds. For example, if a manager has a tick duration of 50 milliseconds and is running an animation with a frame duration of 100 milliseconds, then the manager will advance that animation by one frame every two ticks. On the other hand, if a manager has a tick duration of 100 milliseconds and is running an animation with a frame duration of 50 milliseconds, the manager will advance that animation by two frames on each tick.
Animation managers are started with startAnimationManager and
stopped with stopAnimationManager.
Animations are started with startAnimation and stopped with
stopAnimation. Each animation must be associated with an
application state field accessible with a traversal given to
startAnimation.
When an animation is started, every time it advances a frame, and
when it is ended, the manager communicates these changes to the
application by using the custom event constructor provided to
startAnimationManager. The manager uses that to schedule a state
update which the application is responsible for evaluating. The state
updates are built from the traversals provided to startAnimation.
The manager-updated Animation values in the application state are then drawn with renderAnimation.
Animations in Loop mode are run forever until stopped with
stopAnimation; animations in Once mode run once and are removed
from the application state (set to Nothing) when they finish. All
state updates to the application state are performed by the manager's
custom event mechanism; the application never needs to directly
modify the Animation application state fields except to initialize
them to Nothing.
There is nothing here to prevent an application from running multiple managers, each at a different tick rate. That may have performance consequences, though, due to the loss of batch efficiency in state updates, so we recommend using only one manager per application at a sufficiently short tick duration.