Game Development Reference
In-Depth Information
(float)charData.Y / (float)_texture.Height);
Point bottomRight = new Point( topLeft.X + ((float)charData.Width /
(float)_texture.Width),
topLeft.Y +((float)charData.Height /
(float)_texture.Height));
sprite.SetUVs(topLeft, bottomRight);
sprite.SetWidth(charData.Width);
sprite.SetHeight(charData.Height);
sprite.SetColor(new Color(1, 1, 1, 1));
return new CharacterSprite(sprite, charData);
}
}
The U,V coordinates are provided in pixels, but OpenGL textures are indexed from
0 to 1. Pixels values are converted to OpenGL coordinates by dividing the x and y
pixel coordinates by the width and height of the texture. The CharacterData
numbers are all stored as integers and need to be cast to floats to get a result with
decimal places when dividing. The height and width of the sprite is set using the
CharacterData information, and the color is set to white as a default. Once
thespriteiscreated,itismadeintoa CharacterSprite and returned.
Rendering Text
The font code is now usable. An immediate use for text is an fps, frames per
second, display. The fps will indicate how fast the game code is running. Frames
per second is a measure of how often the game loop is executed per second.
Modern games aim for a frame-rate of 30 or 60 frames per second. The number
of frames per second is not the only factor contributing to smooth graphics; the
consistency of the frame-rate is also important. A game that hovers around
60 fps but sometimes drops to 30 fps will appear more choppy than one that runs
consistently at 30 fps.
Create and add a new game state to the project. I've chosen FPSTestState but
the name doesn't really matter. Make sure it's added to the StateSystem and
is the first state loaded by default. The state requires the TextureManager to
be passed in to the constructor to create the font object. Here is the code to
render some text:
class FPSTestState : IGameObject
{
 
 
Search WWH ::




Custom Search