Game Development Reference
In-Depth Information
We will also specify which of the ease curves we wish to use, and finally we will provide a
way for users to know when an animation has finished.
An animation will provide users the ability to specify three functions, an update function,
this function will be called each frame during an animation. Users may want to inject cus-
tom behaviors at precise points in an animation's lifetime. The ease function, this will be
one of the ease and curve functions we have defined in our curves library. And a finish
function, this is a function called when the animation is finished. Alternatively, instead,
or in addition to, we could trigger an event OnFinished , it would provide another way of
achieving the same result. The function approach may be favorable because it results in
more concise code when constructing an animation, as we will see.
typedef std::function<void(float)> update_function;
typedef std::function<float(float)> ease_function;
typedef std::function<void()> finish_function;
The next important properties of an animation define its behavior, and keep its state.
float m_start;
float m_end;
float m_duration;
float m_time;
There are two types of animations, those that start from some value and end in another
where the user is responsible for providing an update function by which we can use the
results of the interpolation. And, an animation that operates on a reference to an existing
value, external to the animation. The latter will be used more often as we generally have a
value we wish to interpolate.
The constructor for the second type of animation takes a reference to the value, it will then
bind a swap function that will swap the resulting value of the interpolation with the value
in the reference.
animation(float& value, float end, float duration, ease_function easeFunction, finish_function finishFunction = nullptr)
: m_start(value)
, m_end(end)
, m_duration(duration)
, m_time(0)
, m_easeFunction(easeFunction)
, m_finishFunction(finishFunction)
{
using namespace std::placeholders;
m_updateFunction = std::bind( &swap, std::ref(value), _1);
}
Search WWH ::




Custom Search