-
-
Notifications
You must be signed in to change notification settings - Fork 8
Tweens class (Easing waveforms)
The Tweens class is a global singleton tweens
that holds a library of "easing waveforms" that are hard-coded into the framework. You can use these to control lights, fading, movement, scaling and other time-based animations.
Tweens are basically integer-indexed arrays that are of the size 1024 (generally) and are built from either hand-drawn curves or from functions like sine, cosine, tangent, arctangent. There is also a tween that holds the value of "1" -- and you can look them up by name.
You can see a full list of the baked in waveforms (and add your own) in the file Tweens.cpp
Here is some example code to look up a waveform:
#include "Tweens.h"
Zp<Tween> myTween = tweens.find("Humanized In Out");
Once you have looked up a waveform, you can use it to perturb a value if you provide it with a time-based ratio:
/* .. in some object .. */
Zdouble myValue;
void Between() {
expired+=FRAMETIMEd; // A ratio of 1.0 / FPS, coded as 1.0/60.0
myValue = myTween->tweend( fmod(expired,3.0) ); /* fmod(a,b) is the equivalent of integer modulo (remainder), but for decimals */
}
void Render() {
Crayon tint(255.0); // Sets grayscale color of white
tint.Multiply(myValue); /* Causes grayscale color to follow ratio of myValue, which is determined by the Tween you picked */
Rectangle(tint,10,10,300,300);
}
There is a Proce55or derived UI element to select tweens implemented in fx_Tween.h
Additionally, the FastGUI singleton has a tween selector that can be invoked this way:
Zp<Tween> myTween = tweens.One(); // Start as "one"
// in Render()
void Render() {
myTween=fast.tween(myTween, 10, 10, 256, 64 );
}
GraphicsAddict covered this in a video: Tweens and Easing
Find us on YouTube channel "GraphicsAddict" and explore the engine and framework: GraphicsAddict channel on YT