Chapter 3: Helper Classes


Overview

In the Helper namespace I usually put a lot of helpful little tools and classes, which become quite useful over time. For a single project it might not be the most important or valuable code, but because it is used again and again, no matter whether other parts of the engine change, helper classes will be the most consistent part of your engines and projects. Most of the helper classes don’t have much to do with game programming, and they are useful in other projects or even in websites.

You just saw in the previous chapter that you can write a whole game without any helper classes and without even using any extra files or classes at all. But as the projects become bigger and bigger you will see that there are a lot of repeating patterns and similar problems occur, which were already solved in the past. Usually most of the reused functionality in XNA is graphic components. In the next chapter and especially in the second part of this book you learn more about game components and the graphic engine. For now this chapter keeps the focus on the very basic functionality to log messages, access the game content, do unit testing effectively, how to generate random numbers, and many other smaller issues.

To make this chapter a little bit more exciting, you also create another little game just for the fun of it. Not all of the helper classes will be used, but building a game engine is not an easy task. For that reason, this and the next chapter start with the helper classes and the game components to make developing your graphic engine in Part II of this book a little easier. Please note that I did not write the helper classes in the way they are presented in this chapter; they evolved over the course of the past couple of years. Just add functionally or your own helper classes whenever you need them. If you solve a problem once and think it might not be useful again, just leave it where it is. But if you find yourself copying that solution over to a new project or maybe just to another class several times, you should seriously consider extracting the logic and putting it into a special class.

Additionally, you learn a little bit more about the content pipeline you already used in the previous chapters to support the Xbox 360. It is possible to directly load textures or shaders without using the content pipeline, but all these methods work only on the Windows platform. If you want to create a cross-platform game you should make sure everything compiles and works on both the Windows and the Xbox 360 platforms. You will continue to do that throughout this book.

At the end of this chapter you will quickly develop a fun Breakout clone game. It will be a lot easier than in the previous chapter because you will write all the helper classes first. For example, sprite rendering is very easy with the help of the SpriteHelper class. You can find more helper classes and game components to improve both the Pong and Breakout games in the next chapter.




Professional XNA Game Programming
Professional XNA Programming: Building Games for Xbox 360 and Windows with XNA Game Studio 2.0
ISBN: 0470261285
EAN: 2147483647
Year: 2007
Pages: 138

Similar book on Amazon
XNA Game Studio 4.0 Programming: Developing for Windows Phone 7 and Xbox 360 (Developer's Library)
XNA Game Studio 4.0 Programming: Developing for Windows Phone 7 and Xbox 360 (Developer's Library)
Learning XNA 3.0: XNA 3.0 Game Development for the PC, Xbox 360, and Zune
Learning XNA 3.0: XNA 3.0 Game Development for the PC, Xbox 360, and Zune
Beginning XNA 2.0 Game Programming: From Novice to Professional (Expert's Voice in Game Programming)
Beginning XNA 2.0 Game Programming: From Novice to Professional (Expert's Voice in Game Programming)
Microsoftu00ae XNAu00ae Game Studio 3.0: Learn Programming Now! (Pro - Developer)
Microsoftu00ae XNAu00ae Game Studio 3.0: Learn Programming Now! (Pro - Developer)

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net