Single header C++ Tweening file
A simple "library" that allows the user to create tweens easily. It supports:
From
| Start valueTo
| End valueDuration
| Tween timeDelay
| Wait timeEasing
| See EasingYoyo
| tween back in reverseRepeat
| When done, keep playingOnUpdate
| Update callbackOnComplete
| Complete callback
The Only thing you need is TypeTween.hpp
. Download it and include it anywhere in your project.
/* Manager that holds all the tweens */
TypeTween::Manager manager;
/* Specify the type */
TypeTween::Tween<float> tween;
/* Set values of tween */
tween.From(startValue).
To(endValue).
Duration(duration).
Easing(ease).
Yoyo(yoyo).
Repeat(repeat)
.OnUpdate(
[](const float& _value, float t) {
std::cout << "Value: " << _value << " Time: " << t << std::endl;
}
).OnComplete(
[](const float& value) {
std::cout << "Done" << std::endl;
}
);
/* Add it to the manager */
manager.AddTween(tween);
/* In your main loop, update the manager */
while(true){
float deltaTime = 1.0f/60.0f;
manager.Update(deltaTime)
}
Since the tween is templated, any type with a +
, -
, and *
operator will work.
It also contains pointer support. The pointer gets updated, so there is no need for an OnUpdate
callback.
As of right now, it currently supports these easings:
Source easings.net
This repo contains an example.sln. This is just a simple showcase of how to use it and check if everything works as expected.
It started as a simple header that I kept re-using. So I decided to share it here! Feel free to contribute, make issues, make pr's, if you have any suggestions!