137. Sprite Sheet


Sample Overview

Manually combining sprite images into larger sheets works well if you have just a few sprites, but it quickly becomes a burden as your game grows larger. When you have hundreds of sprites, it can be laborious to manually pack them all into a single sprite sheet texture, and then to remember where you put each image so that you know what source rectangle to pass to SpriteBatch.Draw in your game code.


This sample automates the process of creating sprite sheets by using a custom content processor. You provide an XML file listing any number of individual bitmap files, one per sprite. The processor reads all these bitmaps, packs them into a single larger texture, and saves this new texture along with information recording which source rectangle should be used for each sprite. You can then look up your sprites by name, rather than having to remember the specific coordinates for each image.


Downloads