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;