Sprite Sheets Essential facts every game developer should know

In the second part you are going to learn how the performance of your game can be increased with sprite sheets.

Let me introduce OpenGL.
He is the artist painting your game scene at what is called the frame buffer.

The other important component is of course the game itself.

Let’s look at what would happen if you use individual sprites instead of a sprite sheet.

First the game needs to tell OpenGL which sprite to paint.
Next it needs to tell OpenGL which part of the sprite to draw.
And finally it needs to tell him where on the frame to draw the sprite.
With this information, OpenGL starts drawing the scene. But while he is busy, the game has to wait until the next commands can be processed.

This procedure is now repeated until all sprites are drawn. The faster this happens, the higher the frame rate your game is in the end.
As you can see, there is a lot of communication overhead going on between the game and OpenGL. Obviously this is not an ideal solution.

A better solution is to use a sprite sheet, like the one we created in the example before.
For this, we need an additional module in the game called a sprite batch or sprite atlas. This module collects all the data required to draw the sprites:
our reference to the sprite sheet, a list of source coordinates, which contain the parts of the sheet to be copied from,
a list of destination coordinates where the sprites have to be placed on the scene.

Now the communication between the game and OpenGL is quite simple: Set the sprite sheet, set the source coordinate list, set the destination coordinate list.

That’s it.
OpenGL can now draw the scene without further interruption and the game can attend to other tasks like handling players input and calculating collisions and objects movement.

As you can see using sprite sheets has a big win.
They help reduce memory consumption, they speed up the drawing process and they help to keep the frame rate high.