正文

游戲數(shù)學(xué)(28)

精通C#游戲編程 作者:(英)斯庫(kù)勒


 

8.4.2  Tween類

Tween類封裝了表示變量的值隨時(shí)間變化的這種思想。該類的完整代碼如下所示。

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;

 


上一章目錄下一章

Copyright ? 讀書(shū)網(wǎng) hotzeplotz.com 2005-2020, All Rights Reserved.
鄂ICP備15019699號(hào) 鄂公網(wǎng)安備 42010302001612號(hào)