Game Development Reference
In-Depth Information
Figure 9.9
Incorrect texturing.
texture so it seems squashed compared to the second spaceship sprite, which has
both correct dimensions and the correct texture.
The problem here is that the OpenGL is never being told when the texture chan-
ges. If it doesn't know, it uses whatever texture was set last. In the game loop a lot
of texture changing per frame can slow things down, but a moderate amount of
texture changing is nothing to worry about and indeed is essential for most games.
The class that needs to be modified is the Renderer class. The Renderer class
batches up all the sprites so that they can be sent to the graphics card all at once.
At the moment the Renderer class doesn't check which texture a sprite uses. It
needs to check to see if it's drawing something with a new texture. If it is, then it
can tell OpenGL to draw whatever has been batched so far with the old texture
and then start a new batch using this new texture.
Here's the current Renderer.DrawSprite code.
public void DrawSprite(Sprite sprite)
{
_batch.AddSprite(sprite);
}
 
Search WWH ::




Custom Search