Game Development Reference
In-Depth Information
public void Render()
{
_batch.Draw();
}
}
Converting the renderer class is very simple: a Batch object is added as a
member, and sprites are added to this when drawn. There is one additional
method called Render , which has been added; this needs to be called every
frame. If there is anything left in the batch that hasn't been drawn by the end of
the frame, then Render will ensure it gets drawn.
The Renderer currently doesn't handle different textures very well. As all the
sprites are drawn in a big batch, all the sprites in that batch must have the same
texture. An easy way to handle this is to do a texture check each addition, and if
the texture is different draw the batch.
Profiling the Batch DrawMethod
Text will render just as before, but now it will be faster. If the previous example of
rendering around 10,000 sprites is repeated, the frame-rate on my computer
jumps from around 30 fps to over 80 fps—a significant increase. This will mean
older computers will be much more likely to run smoothly.
Summary
Now you've added text drawing capabilities to your code library and improved
the sprite rendering code. It's nearly time to jump in and create a game, but
before that, we'll take a closer look at the math used in games.
 
 
Search WWH ::




Custom Search