Game Development Reference
In-Depth Information
The font file needs to be loaded in the Form.cs. If we were dealing with many
fonts, it might be worth creating a
FontManager
class, but because we're only
using one or two they can just be stored as member variables. Here is the code to
load the font files.
private void InitializeTextures()
{
// Init DevIl
Il.ilInit();
Ilu.iluInit();
Ilut.ilutInit();
Ilut.ilutRenderer(Ilut.ILUT_OPENGL);
// Textures are loaded here.
_textureManager.LoadTexture("title_font", "title_font.tga");
}
Engine.Font _titleFont;
private void InitializeFonts()
{
_titleFont
¼
new Engine.Font(_textureManager.Get("title_font"),
FontParser.Parse("title_font.fnt"));
}
The font texture is loaded in the
IntializeTextures
function and this is
used when the font object is created in the
IntializeFonts
method.
The title font can then be passed into the
StartMenuState
constructor. Add
the following new
StartMenuState
to the Shooter project.
class StartMenuState : IGameObject
{
Renderer _renderer
¼
new Renderer();
Text
_title;
public StartMenuState(Engine.Font titleFont)
{
_title
¼
new Text("Shooter", titleFont);
_title.SetColor(new Color(0, 0, 0, 1));
// Center on the x and place somewhere near the top
_title.SetPosition(-_title.Width/2,300);
}
Search WWH ::
Custom Search