Game Development Reference
In-Depth Information
These graphs look interesting, but without a game application, they may seem
academic and rather dull. Next, these functions will be used to animate sprites.
Trigonometric Functions for Special Effects
Create a new game state called SpecialEffectsState . This state will de-
monstrate how to use the sine and cosine functions that have just been covered
to create cool special effects with the text class.
class SpecialEffectState : IGameObject
{
Font _font;
Text _text;
Renderer _renderer = new Renderer();
double _totalTime = 0;
public SpecialEffectState(TextureManager manager)
{
_font = new Font(manager.Get("font"), FontParser.Parse("font.fnt"));
_text = new Text("Hello", _font);
}
public void Update(double elapsedTime)
{
}
public void Render()
{
Gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
_renderer.DrawText(_text);
_renderer.Render();
}
}
The basic state just renders out the text ''Hello.'' It's very easy to use the sine
value to make this text pulse the opacity from 0-1 and back again. Text is used
here, but it could just as easily be a sprite or model.
public void Update(double elapsedTime)
{
 
Search WWH ::




Custom Search