Game Development Reference
In-Depth Information
{
if (_tween.IsFinished() != true)
{
_tween.Update(elapsedTime);
_sprite.SetWidth((float)_tween.Value());
_sprite.SetHeight((float)_tween.Value());
}
}
}
The tween object is used to make a sprite grow from nothing to a size of 256
over a period of 5 seconds. Here, the tween constructor takes three arguments.
The first argument is the start value, the second is the destination value, and the
final argument is the time to go from the start value to the second value.
The Update loop checks if the tween has finished. If it hasn't, it updates the tween.
The width and height are set to the tween's value—somewhere from 0 to 256.
With the above example, the tween linearly moves from start to end. This means
after 2.5 seconds the value of the tween will be 128. Tweens don't have to be
linear; they accelerate or decelerate to their destinations. This power to change
the type of tween comes from representing position as a function over time.
public void function(double time)
{
// Create a position using the time value
return position;
}
The actual tween function is a little more complicated than that. Here is the
function that performs linear interpolation.
public static double Linear(double timePassed, double start, double dis-
tance, double duration)
{
return distance * timePassed / duration þ start;
}
The tween code uses a linear tween by default, but many different tweens can be
added. Figure 8.20 shows a number of these tweens.
There are many Flash tween functions available on the internet, and it's very easy
to convert these to C# code.
 
Search WWH ::




Custom Search