HAPPY BOOKSGIVING
Use code BOOKSGIVING during checkout to save 40%-55% on books and eBooks. Shop now.
Register your product to gain access to bonus material or receive a coupon.
This eBook includes the following formats, accessible from your Account page after purchase:
EPUB The open industry format known for its reflowable content and usability on supported mobile devices.
PDF The popular standard, used most often with the free Acrobat® Reader® software.
This eBook requires no passwords or activation to read. We customize your eBook by discreetly watermarking it with your name, making it uniquely yours.
Get Started Fast with XNA Game Studio 4.0–and Build Great Games for Both Windows® Phone 7 and Xbox 360®
This is the industry’s best reference and tutorial for all aspects of XNA Game Studio 4.0 programming on all supported platforms, from Xbox 360 to Windows Phone 7 and Windows PCs. The only game development book authored by Microsoft XNA development team members, it offers deep insider insights you won’t get anywhere else–including thorough coverage of new Windows Phone APIs for mobile game development.
You’ll quickly build simple games and get comfortable with Microsoft’s powerful XNA Game Studio 4.0 toolset. Next, you’ll drill down into every area of XNA, including graphics, input, audio, video, storage, GamerServices, and networking. Miller and Johnson present especially thorough coverage of 3D graphics, from Reach and HiDef to textures, effects, and avatars. Throughout, they introduce new concepts with downloadable code examples designed to help you jumpstart your own projects. Coverage includes
From Windows Phone 7 mobile gaming to Xbox 360, XNA Game Studio 4.0 creates huge new opportunities for experienced Microsoft developers. This book helps you build on skills you already have, to create the compelling games millions of users are searching for.
Introduction 1
So You Want to be a Game Developer? 1
A Brief History of XNA Game Studio 1
What Is Available in Game Studio 4.0? 3
Why This Book? 4
1 Getting Started 5
Installing XNA Game Studio 4.0 5
Downloading the Tools 6
App Hub Membership 6
XNA Game Studio Connect 9
Writing Your First Game 11
Your First XNA Game Studio Windows Game 11
Your First XNA Game Studio XNA Xbox 360 Game 11
Your First XNA Game Studio Windows Phone 7
Game 12
Download Samples 12
Summary 12
2 Sprites and 2D Graphics 13
What Does 2D Mean? 13
Show Me Something on Screen 14
Spritebatch 16
Drawing 16
Moving Things Around 19
Animation 20
Controlling State 21
Rendering Text 25
Summary 27
3 The Game Object and the Default Game Loop 29
What Is in a New Project? 29
The Game Class 32
Virtual Methods 32
Methods 33
Properties 34
GameTime 34
Game Loop 36
Update and Draw 36
Components 38
GameComponents 38
Summary 40
4 Introduction to 3D Graphics 41
3D Graphics in XNA Game Studio 41
What Are 3D Graphics? 42
Makeup of a 3D Image 42
3D Math Basics 43
Coordinate Systems 44
Vectors in 3D Graphics 46
Matrix 53
Graphics Pipeline 61
Graphics Card 62
Vertex Shader 62
Backface Culling 63
Viewport Clipping 63
Rasterization 64
Pixel Shader 64
Pixel Tests 64
Blending 65
Final Output 65
Reach and HiDef Graphics Profiles 65
Graphics Profiles Define Platform Capabilities 66
The Reach Profile 66
The HiDef Profile 66
Let the 3D Rendering Start 67
GraphicsAdapter 67
GraphicsDevice 69
Drawing with Primitives 71
Summary 83
5 Lights, Camera, Action! 85
Why Do I See What I See? 85
View Matrix 87
Projection Matrix 88
Perspective 89
Orthographic 93
Camera Types 93
Static Cameras 94
Models 95
What Is a Model? 95
Rendering Models 99
Summary 103
6 Built-In Shader Effects 105
Using BasicEffect 106
Basic Lighting 108
Textures, Vertex Colors, and Fog 114
Using the Effect Interfaces 121
Using DualTextureEffect 122
Using AlphaTestEffect 124
Using EnvironmentMapEffect 124
Using SkinnedEffect 127
Summary 140
7 States, Blending, and Textures 141
Device States 141
BlendState 142
DepthStencilState 149
Render Targets 155
Faking a Shadow with a Depth Buffer and Render
Targets 158
Back to Device States 161
The Stencil Buffer 161
RasterizerState 164
SamplerStates 166
Other Texture Types 169
Summary 170
8 Introduction to Custom Effects 171
What Is a Custom Effect? 171
High Level Shading Language 172
Creating Your First Custom Effect 172
Parts of an Effect File 173
Global Variables 174
Vertex Structures 174
Drawing with a Custom Effect 177
Vertex Color 179
Texturing 180
Setting Sampler States in Effect File 183
Textures Repeating 184
Lighting 186
Ambient Lighting 186
Triangle Normals 190
Diffuse Lighting 192
Emissive Lighting 198
Specular Lighting 199
Fog 202
Point Lights 206
Effect States 209
Alpha Blending Using Effect States 211
Summary 213
9 Using the Content Pipeline 215
Tracing Content Through the Build System 215
Content Processors 216
Content Importers 223
Combining It All and Building Assets 226
Combining What You Learned So Far 235
Summary 238
10 Having Fun with Avatars 239
Introduction to Avatars 239
Accessing Avatar Information Using
AvatarDescription 240
Loading Avatar Animations with AvatarAnimation 243
Drawing the Avatar Using AvatarRenderer 246
Modifying Avatar Lighting 248
Playing Multiple Animations 249
Blending Between Animations 253
Interacting with Objects 260
2D Avatars Using Render Targets 263
Custom Avatar Animations 265
Creating the Custom Animation 266
Building the Custom Animation Type 267
Creating the Content Processor 273
Adding the Custom Animation to Your Game 283
Updating Your Game to Use the Custom
Animation 284
Summary 285
11 Understanding Performance 287
General Performance 287
Who Takes Out the Garbage? 289
Multithreading 292
Graphics Performance 293
Measuring Performance 295
Performance Measurement Tools 306
Cost of Built-In Shaders 307
Summary 309
12 Adding Interactivity with User Input 311
Using Input in XNA Game Studio 311
Polling versus Event-Based Input 312
The Many Keys Of A Keyboard 312
Reading Keyboard State 313
Moving Sprite Based on Keyboard Input 315
Onscreen Keyboard 316
Precision Control of a Mouse 320
Reading Mouse State 320
Moving Sprite Based on Mouse Input 322
Setting the Mouse Position 324
Xbox 360 Gamepad 324
Reading Gamepad State 325
Moving Sprites Based on Gamepad Input 329
Thumb Stick Dead Zones 332
Other Types of Controllers 332
Is the Gamepad Connected? 333
Multitouch Input For Windows Phones 334
Reading the TouchPanel Device State 334
Determine Number of Touch Points 336
TouchPanel Width, Height, and Orientation 337
Moving Sprite Based on Multitouch Input 337
Reading Gestures from the TouchPanel 339
Displaying GestureSample Data 341
Windows Phone Sensors and Feedback 342
Acceleration Data using the Accelerometer 344
Locating a Windows Phone with the Location
Service 348
Providing User Feedback using Vibration 351
Summary 351
13 Turn Up the Volume 353
Playing Sound Effects 353
Using SoundEffect for Audio Playback 354
Microsoft Cross-Platform Audio Creations
Tool (XACT) 360
Dynamic Sound Effects 368
Recording Audio with a Microphone 368
Generating Dynamic Sound Effects 371
Summary 374
14 Storage 375
What Is Storage? 375
Isolated Storage 375
Saving and Loading Data 377
The IsolatedStorageFile Object 379
XNA Game Studio Storage 380
Recreating the Project on Xbox 380
Devices and Containers 382
Getting a Device 383
Looking at the API 387
Loading Loose Files from Your Project 388
Summary 390
15 Gamer Services 391
GamerServicesComponent 391
Guide Class 392
Trial Mode 392
Now the Bad News 397
Platform-Specific Guide Functionality 397
Gamers and Profiles 402
GameDefaults 405
Presence 406
Privileges 406
With Friends Like This... 407
Summary 408
16 Multiplayer Networking 409
Multiplayer Games 409
Getting Ready for Networking Development 410
Main Menu and State Management 412
Creating a Network Session 416
Building a Game Lobby 423
Playing the Game 425
Searching for an Available Network Session 430
Joining an Available Network Session 435
Sending Player Invites 438
Simulating Real World Network Conditions 439
Summary 440
17 Using Media in XNA Game Studio 441
What Is Media? 441
Playing a Song 441
MediaPlayer 442
Songs and Metadata 443
Media Enumeration 444
Media Library 444
Video 448
Rendering a Video 448
Visualizations 451
Rendering Visualization Data 451
Summary 453
A Reach vs. HiDef Chart 455
B Using the Windows Phone FMRadio 459
C Windows Phone 7 Launchers and Choosers 463
D Dealing with Tombstoning 479
Index 487