Game Development Reference
In-Depth Information
There are two constructors and both call the Construct method. The con-
structors allow a user to specify the type of tween function, or alternatively just
use the default linear change over time. A tween function is defined by the
TweenFunction delegate. The only implementation of the TweenFunction
delegate in this class is the Linear function. Its use can be seen in the default
constructor.
Construct(start, end, time, Tween.Linear);
The Construct method records the start value of the tween, the end value, and
the time in which the tween can perform this operation. A tween function can also
be passed in to determine how the value will be changed over time. The Con-
struct method records these values and works out the distance from the start
value to the end value. This distance is passed on to the relevant tween function.
The Tween object is updated every frame and the time elapsed is summed each
Update call. This way the Tween object knows how far through the tween it is.
The tween function delegate modifies the current value of the tween. Finally, the
Update method checks if the tween has finished, and if it has, it sets the finish
flag to true.
With only a linear function, the Tween class isn't very exciting, so here are some
more functions that can be added. These are shown in Figure 8.20.
public static double EaseOutExpo(double timePassed, double start, double
distance, double duration)
{
if (timePassed == duration)
{
return start + distance;
}
return distance * (-Math.Pow(2, -10 * timePassed / duration) + 1) + start;
}
public static double EaseInExpo(double timePassed, double start, double
distance, double duration)
{
if (timePassed == 0)
{
return start;
}
 
Search WWH ::




Custom Search