Game Development Reference
In-Depth Information
TextureManager _textureManager;
Font _font;
Text _fpsText;
Renderer _renderer = new Renderer();
public FPSTestState(TextureManager textureManager)
{
_textureManager = textureManager;
_font = new Font(textureManager.Get("font"),
FontParser.Parse("font.fnt"));
_fpsText = new Text("FPS:", _font);
}
#region IGameObject Members
public void Render()
{
Gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
_renderer.DrawText(_fpsText);
}
public void Update(double elapsedTime)
{
}
#endregion
}
Before the code can be tested, the DrawText call for the Renderer needs to be
written. This will draw the text to the middle of the screen, which is fine for now.
The DrawText method goes through the text and draws each sprite.
public void DrawText(Text text)
{
foreach (CharacterSprite c in text.CharacterSprites)
{
DrawSprite(c.Sprite);
}
}
Once this is added to the renderer, running the code will render the text ''FPS:''
to the screen, as can be seen in Figure 7.4.
Calculating the FPS
The frames per second is simple to calculate. The number of frames in a second
need to be counted; then this number needs to be displayed to the screen. The
 
Search WWH ::




Custom Search