The game world – tile-based maps

At a screen size of 800 by 600 pixels, an image filling the screen contains 480,000 individual pixels. If these pixels are stored as 32-bit values (8 bits each for red, green, blue, and alpha) this means that each "screen" of pixels occupies 1875 kilobytes of memory. That does not sound too bad on the surface—after all, computers have lots of memory, and 1.8 megabytes for an image is not all that much memory.

In that case, when making a world that is larger than a single screen, why not just make a huge bitmap to use as the background and scroll across it? Unfortunately, there are a couple of problems with this approach.

First, many graphics cards have a maximum texture size. On Windows, 2048 by 2048 is a common ...

Get XNA 4.0 Game Development by Example Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.