Game Development Reference
In-Depth Information
Using the CharacterData
Here is a high-level look at how the text system will work. A new state has been
created that shows the font system in action.
class TextRenderState : IGameObject
{
TextureManager _textureManager;
Font _font;
Text _helloWorld;
Renderer _renderer = new Renderer();
public TextRenderState(TextureManager textureManager)
{
_textureManager = textureManager;
_font = new Font(textureManager.Get("font"),
FontParser.Parse("font.fnt"));
_helloWorld = new Text("Hello", _font);
}
public void Render()
{
Gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
_renderer.DrawText(_helloWorld);
}
public void Update(double elapsedTime)
{
}
}
There are two new classes in use here. First is a
Font
class, which determines
what font will be used. The
Font
class contains a reference to the font texture
and the character data. The second class is the
Text
class that is used to render
text. Several different fonts could be loaded in and it would be very easy to swap
between them.
The
Renderer
has been given an extra method called
DrawText
.
DrawText
takes a text object and uses it to render text. The text class will just be a collection
of sprites so the renderer can reuse its
DrawSprite
code.
There is another class that isn't in the example; it's a class to represent the in-
dividual characters in the bitmap text string. It's called the
CharacterSprite
class and has only two members: one is the sprite representing the letter and one
Search WWH ::
Custom Search