8.4.2 Tween類
Tween類封裝了表示變量的值隨時間變化的這種思想。該類的完整代碼如下所示。
public class Tween
{
double _original;
double _distance;
double _current;
double _totalTimePassed = 0;
double _totalDuration = 5;
bool _finished = false;
TweenFunction _tweenF = null;
public delegate double TweenFunction(double timePassed, double start,
double distance, double duration);
public double Value()
{
return _current;
}
public bool IsFinished()
{
return _finished;
}
public static double Linear(double timePassed, double start, double
distance, double duration)
{
return distance * timePassed / duration t start;
}
public Tween(double start, double end, double time)
{
Construct(start, end, time, Tween.Linear);
}
public Tween(double start, double end, double time, TweenFunction
tweenF)
{
Construct(start, end, time, tweenF);
}
public void Construct(double start, double end, double time, TweenFunction
tweenF)
{
_distance = end - start;
_original = start;
_current = start;
_totalDuration = time;