It has been a while since the last update. As I mentioned already a few times, I wasn't exactly happy with some limitations of the Animations module, for example the need to copy animations for every animator or to manually track progress, e.g. to know when an animation has finished. In the meantime, I have addressed many of those issues. That's why I'm now announcing a major improvement of the
thor::Animator API.
Animation mapsThe Thor 2.0
Animator stores all the animations and tracks a progress. Since different animated objects (e.g. sprites) have different animation progress, one needs to duplicate the
Animator instance, and with it all the stored animations. Thor 2.1 changes this by splitting the functionality in two classes:
Animator that tracks progress and animates an object, and
AnimationMap which stores the animations. The former references the latter. Animation maps are resource-style classes, this separation is comparable to
sf::Sprite and
sf::Texture.
thor::AnimationMap<sf::Sprite, std::string> animations;
animations.addAnimation("anim1", ...);
thor::Animator<sf::Sprite, std::string> animator(animations);
Queued animationsIt is now finally possible to queue multiple animations. Thus, one need no longer keep track of an animation, and code like
if (finished) startNewAnimation() is history. The API is very simple and expressive, thanks to operator overloading. The
play() function plays some animations and resets the queue, the
queue() function appends to the end.
thor::Animator<sf::Sprite, std::string> animator;
// Play anim1, then anim2
animator.play() << "anim1" << "anim2";
// Append further animations to the queue
animator.queue() << "anim3";
Playback schemes and notificationsAnother new feature are playback schemes. They give more control over the playback of animations. So far, I have implemented
repeat() to repeat an animation a finite number of times and
loop() to repeat it indefinitely. They're very easy-to-use with the queue syntax (which was not straightforward to implement, there's some heavy metaprogramming behind the scenes):
// Play one animation, then 3 times another, then loop a third one
animator.play()
<< "anim1"
<< thor::Playback::repeat("anim2", 3)
<< thor::Playback::loop("anim3");
Furthermore, you can be notified when an animation starts or finishes. You can register a callback that does virtually anything. The SDK example uses it to output the playing animation. On the other hand, explicit polling functions like
isPlayingAnimation() and
getPlayingAnimation() have been removed.
animator.play()
<< "anim1"
<< thor::Playback::notify([] () { std::cout << "Finished!\n"; });
Keep in mind that this entire API is generic. You don't have to use it to animate SFML objects, you can do anything it permits. It needn't even be an animation, you can also use it for other logic that is updated based on a progress.
You can get an overview over the new functionality
on my homepage. You can directly use it by checking out the latest revision on
GitHub. Have fun!