Saturday, July 31, 2010

Sprite Lib Nearly Finished...

For the longest time, I have not had any formal 2D support for my game. I did not have a good system designed to minimize draw calls and vertex bandwidth until I took a second look at XNA. The XNA framework handles sprites by accomplishing my objectives, and this is how it works:
it batches sprites together.

There are some problems with this, however... The XNA sprite batch works in sort of an immediate mode where you must allocate your sprite data per draw group. The programmer signals when to start and stop allocating with the sprite batch's Begin() and End() methods...

Nevertheless, I took this same approach, and I think it will be a success! I do not follow XNA's example too closely, and in fact, I mix things up quite a bit! What I did was bring back the old sprite class I used to have back when I worked on the PSP, only this time, instead of having a texture reference, each sprite has a reference to a sprite batch class...

Here's how it works:
1) SpriteBatch Class:
  • Loads the texture the sprite batch will use
  • Creates/Deletes sprite instances
  • Stores all vertex data per sprite instance into a single STL vector
  • Stores a separate index lookup STL vector that works in parallel with the vertex list
  • Does all drawing in one function call
2) Sprite Class:
  • Holds data for a single sprite definition
  • Is created/deleted from its parent sprite batch
  • Does not directly store vertex data
  • Does not directly have access to vertex data
  • Has a matching index number to the vertex data in the parenting sprite batch
I have some of the functionality there, and I'm close to having the whole sprite class running. When it is finished, I'll setup a simple demo of it working, and post a video.

No comments:

Post a Comment