Gamedev Framework (gf)  0.8.0
A C++14 framework for 2D games
Public Types | Public Member Functions | List of all members
gf::Tween< T > Class Template Reference

An interpolation between two values. More...

#include <gf/Tween.h>

Public Types

using Setter = std::function< void(const T &)>
 A setter function. More...
 

Public Member Functions

 Tween (T origin, T target, Setter setter, Time duration, Easing easing=Ease::linear)
 Constructor with a setter. More...
 
 Tween (T origin, T target, T &value, Time duration, Easing easing=Ease::linear)
 Constructor with a reference. More...
 
void setOrigin (T origin)
 Change the origin of the tween. More...
 
constexpr T getOrigin () const noexcept
 Get the origin of the tween. More...
 
void setTarget (T target)
 Change the target of the tween. More...
 
constexpr T getTarget () const noexcept
 Get the target of the tween. More...
 
void setDuration (Time duration)
 Change the duration of the tween. More...
 
constexpr Time getDuration () const noexcept
 Get the duration of the tween. More...
 
T getValue () const
 Get the current value of the tween. More...
 
bool isFinished () const
 Check if the tween is finished. More...
 
void update (Time time)
 Update the tween. More...
 
void restart ()
 Restart the tween. More...
 

Detailed Description

template<typename T>
class gf::Tween< T >

An interpolation between two values.

See also
Inbetweening - Wikipedia

Member Typedef Documentation

◆ Setter

template<typename T>
using gf::Tween< T >::Setter = std::function<void(const T&)>

A setter function.

Constructor & Destructor Documentation

◆ Tween() [1/2]

template<typename T>
gf::Tween< T >::Tween ( T  origin,
T  target,
Setter  setter,
Time  duration,
Easing  easing = Ease::linear 
)
inline

Constructor with a setter.

Parameters
originThe origin value
targetThe target value
setterThe setter
durationThe duration of the tween
easingThe easing for the interpolation

◆ Tween() [2/2]

template<typename T>
gf::Tween< T >::Tween ( T  origin,
T  target,
T value,
Time  duration,
Easing  easing = Ease::linear 
)
inline

Constructor with a reference.

Parameters
originThe origin value
targetThe target value
valueA reference on the value
durationThe duration of the tween
easingThe easing for the interpolation

Member Function Documentation

◆ getDuration()

template<typename T>
constexpr Time gf::Tween< T >::getDuration ( ) const
inlinenoexcept

Get the duration of the tween.

Returns
The current duration

◆ getOrigin()

template<typename T>
constexpr T gf::Tween< T >::getOrigin ( ) const
inlinenoexcept

Get the origin of the tween.

Returns
The current origin

◆ getTarget()

template<typename T>
constexpr T gf::Tween< T >::getTarget ( ) const
inlinenoexcept

Get the target of the tween.

Returns
The current target

◆ getValue()

template<typename T>
T gf::Tween< T >::getValue ( ) const
inline

Get the current value of the tween.

Returns
The interpolated value

◆ isFinished()

template<typename T>
bool gf::Tween< T >::isFinished ( ) const
inline

Check if the tween is finished.

Returns
True if the tween is finished

◆ restart()

template<typename T>
void gf::Tween< T >::restart ( )
inline

Restart the tween.

◆ setDuration()

template<typename T>
void gf::Tween< T >::setDuration ( Time  duration)
inline

Change the duration of the tween.

Parameters
durationThe new duration

◆ setOrigin()

template<typename T>
void gf::Tween< T >::setOrigin ( T  origin)
inline

Change the origin of the tween.

Parameters
originThe new origin

◆ setTarget()

template<typename T>
void gf::Tween< T >::setTarget ( T  target)
inline

Change the target of the tween.

Parameters
targetThe new target

◆ update()

template<typename T>
void gf::Tween< T >::update ( Time  time)
inline

Update the tween.

Parameters
timeThe time since the last update