Book Image

XNA 4 3D Game Development by Example: Beginner's Guide

By : Kurt Jaegers
Book Image

XNA 4 3D Game Development by Example: Beginner's Guide

By: Kurt Jaegers

Overview of this book

Move beyond the world of flat 2D-based game development and discover how to create your own exciting 3D games with Microsoft XNA 4.0. Create a 3D maze, fire shells at enemy tanks, and drive a rover on the surface of Mars while being attacked by alien saucers."XNA 4 3D Game Development by Example: Beginner's Guide" takes you step-by-step through the creation of three different 3D video games with Microsoft XNA 4.0. Learn by doing as you explore the worlds of 3D graphics and game design.This book takes a step-by-step approach to building 3D games with Microsoft XNA, describing each section of code in depth and explaining the topics and concepts covered in detail. From the basics of a 3D camera system to an introduction to writing DirectX shader code, the games in this book cover a wide variety of both 3D graphics and game design topics. Generate random mazes, load and animate 3D models, create particle-based explosions, and combine 2D and 3D techniques to build a user interface."XNA 4 3D Game Development by Example: Beginner's Guide" will give you the knowledge to bring your own 3D game creations to life.
Table of Contents (16 chapters)
XNA 4 3D Game Development by Example Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface

Time for action – creating a square texture


Add the following code snippet to the LoadContent() method:

letterFont = Content.Load<SpriteFont>("Segoe14");
playerSquare = Content.Load<Texture2D>("Square");

CheckForNewWord();

What just happened?

The default Content object can be used to load any type of asset from our content project into an appropriate instance in memory. The type identifier in angle brackets after the Load() method name identifies the type of content we will be loading, while the parameter passed to the Load() method specifies the asset name of the content.

Asset names can be set via the Properties window in Visual Studio, but would default to the name of the content file, path included, without an extension. Since all of the content objects will be translated into .xnb files by the content pipeline, there is no need to specify the format that the file was in before it was processed.

In our case, both of our content items are in the root of the content project's file structure. It is possible (and recommended) to create subdirectories to organize your content assets, in which case you would need to specify the relative path as part of the asset name. For example, if the Segoe14 sprite font was located in a folder off the root of the content project called Fonts, the default asset name would be Fonts\Segoe14.

Note

Special characters in asset names

If you do organize your assets into folders (and you should!) your asset names will include the backslash character (\) in them. Because C# interprets this as an escape sequence in a string, we need to specify the name in the Content.Load() call as either "Fonts\\Segoe14" or @"Fonts\Segoe14". Two backslashes are treated as a single backslash by C#. Prefacing a string with the @ symbol lets C# know that we are not using escape sequences in the string so we can use single backslash characters. A string prefaced with the @ symbol is called a verbatim string literal.

The last thing our LoadContent() method does is call the (as yet undefined) checkForNewWord() method. We will construct this method towards the end of this chapter in order to generate a new word both at the beginning of the game and when the player has completed spelling the current word.