
Lets have a look at the image we are using for displaying text:
Ah okay, so from what we did earlier we could of just made an animated sprite..right?
Right! However, we have done that already, so I thought I would use a different technique
this time to show you an alternative way to poke around with what the final sprite will look
like. After we created the sprite there is a line underneath called:
fixUV( czText[i]);
Lets have a look at the code for this function:
void fixUV( char c )
{
// we have the ascii code of the letter to draw, we dont have the entire character set in
our font image however
// so we offset it to line up with our image
c -= 33;
© 2007 The Game Creators Ltd. All Rights Reserved.
float U = 0.0f;
float V = 0.0f;
int iY = c / 8;
int iX = c % 8;
float fOffset = 1.0f / 8.0f;
U = iX * fOffset;
V = iY * fOffset;
// 4 vertices in a sprites (quad), we adjust the U and V ( think x and y) coordinates of the
texture to show only the letter we want
// rather than the whole texture
dbSetSpriteTextureCoord ( iNextTextSprite , 0 , U , V );
dbSetSpriteTextureCoord ( iNextTextSprite , 1 , U + fOffset , V );
dbSetSpriteTextureCoord ( iNextTextSprite , 2 , U , V + fOffset );
dbSetSpriteTextureCoord ( iNextTextSprite , 3 , U + fOffset , V + fOffset );
}
This introduces us to UV Coordinates. What are UV Coordinates you are probably
wondering.
Firstly, one thing I should explain, is that although our game is what would be called “2D”,
our sprites in GDK are actually 3D models, very flat looking models granted, but 3D none
the less. Each sprite is infact made up of two triangles forming a square which makes our
sprite. A triangle is made up of three points, or “vertices” which describe the triangle. In the
case of our sprites, 4 vertices are used which the 2 triangles share.
