Game Development Reference
In-Depth Information
public void SetPosition(double x, double y)
{
CreateText(x, y);
}
With the Text classes SetPosition method defined, it can be used in the
Update loop to create a new text-based special effect.
public void Update(double elapsedTime)
{
double frequency = 7;
double _wavyNumberX = Math.Sin(_totalTime*frequency)*15;
double _wavyNumberY = Math.Cos(_totalTime*frequency)*15;
_text.SetPosition(_wavyNumberX, _wavyNumberY);
_totalTime += elapsedTime;
}
This will move the text in a rough circle. This time the numbers don't need to be
scaled between 0 and 1; instead, they are increased so the movement of the text is
very obvious. Different functions can be used to alter the position of the text as
needed.
Finally, this last example takes each letter of the text and animates it as if a wave
was passing along the word. To animate each individual character of the text, a
new GetPosition method must be added to the Sprite class. The sprite
position is taken from the center of the sprite.
public Vector GetPosition()
{
return GetCenter();
}
With the above code added to the Sprite class, the new GetPosition
method can be used in the Update loop.
public void Update(double elapsedTime)
{
double frequency = 7;
int xAdvance = 0;
foreach (CharacterSprite cs in _text.CharacterSprites)
 
Search WWH ::




Custom Search