Contents
Introduction.............................xi
Chapter 1 XNAFrameworkandGameStudio............1
WhatIsXNA?............................1
WhatIstheXNAFramework?...................2
GameAssembly.........................2
GameClass..........................2
GameComponent/DrawableGameComponentClass....5
GameServiceContainerClass ................5
GameTimeClass.......................6
GameWindowClass......................6
GraphicsDeviceManager...................6
FrameworkNamespaceInterfaces..............9
PipelineAssembly.......................10
FrameworkAssembly .....................11
WhatIsXNAGameStudio?....................17
Installing XNA Game Studio ...................18
ProjectTypes............................19
WindowsGame.........................19
WindowsGameLibrary ....................23
Xbox360Game.........................23
Xbox360GameLibrary....................23
StarterKits.............................23
Spacewar ............................24
Marblets.............................24
RacingGame..........................25
ShipGame............................25
ContentPipelineOverview....................26
Summary..............................28
Chapter 2 GameDevelopmentOverview .............29
PartsofaGame ..........................29
Graphics.............................30
InputDevice(s).........................31
Networking...........................32
AI ................................34
GUI/UserInterface.......................35
PhysicsSystem.........................35
iii
Sound/Music ..........................36
GameStates............................37
TheGameLoopXNAStyle..................41
CalculatingFrameRate......................42
GameComponents.........................43
GameServices...........................46
CreatingYourFirstApplication..................51
Chapter 3 2DGraphics.......................63
Texture2D.............................64
SpriteBatch.............................66
Rotation.............................69
Scaling..............................71
Flipping.............................72
Transparency..........................73
Coloring.............................76
Tiling...............................79
AnimatingSprites.........................84
MultipleBatchRendering.....................86
TextDrawing............................88
RenderingwithMultipleViewports ...............92
2DShooterGameVersion1....................96
PlayerandEnemySprites...................97
ShowingtheScore,FrameRate,andCountdown......105
Summary.............................110
Chapter 4 Input ..........................111
Gamepad, Keyboard, and Mouse Classes ............111
Gamepad............................112
Keyboard............................114
Mouse.............................114
<Device>State Classes .....................114
GamePadState.........................115
KeyboardState.........................116
MouseState..........................117
Controlling Sprite Movement ..................118
Collision Detection ........................118
Rectangle Collision Detection ................119
Per-pixel Collision Detection .................125
Transformed Sprite Collision Detection ...........127
CreatingaConfigurableControlSystem............133
2DShooterGameVersion2...................142
Running and Gunning .....................156
SettingUpUser-ConfigurableControls.............182
Contents
iv
Chapter 5 Sound..........................189
XACTandSoundCreation....................191
Playing2DSound.........................194
Playing3DSound.........................198
2DShooterGameVersion3...................200
AddingMusicandSound...................200
Summary.............................202
Chapter 6 I/O ...........................203
The StorageDevice and StorageContainer Classes ......204
StandardI/OFilesandOperations................206
DataSerialization.........................209
2DShooterGameVersion4...................213
Chapter 7 BasicEffects.......................223
BasicEffectClassMethods....................224
Colors,Textures,andAlpha...................227
ImplementingTexturedModels...............228
FoginXNA............................232
ImplementingFog.......................233
Lighting..............................237
EmissiveandAmbientLight.................239
DiffuseLight..........................241
SpecularLight.........................242
ImplementingLighting....................243
AdditionalBasicEffectInformation...............246
Summary.............................248
Chapter 8 3DMathBasics.....................249
Vectors ..............................249
VectorArithmetic.......................251
ClampingwithVectors....................254
TheCrossProduct ......................255
DistancebetweenVectors..................256
TheDotProduct........................256
TheLengthofaVector....................257
InterpolatingVectors.....................257
FindingtheMinimumandMaximumVector ........258
NegatingVectors .......................259
NormalizingVectors......................260
ReflectingVectors.......................260
SmoothInterpolation.....................261
Vector/MatrixTransformation................262
AdditionalVectorOperations.................263
Contents
v
Matrices..............................267
MatrixOperations.......................270
QuaternionRotations.......................277
QuaternionFields,Properties,andFunctions........278
Rays................................280
RayPropertiesandOperations................282
Planes...............................283
PlanePropertiesandOperations...............283
BoundingGeometry.......................285
BoundingSpheres,Boxes,andFrustums..........285
Summary.............................292
Chapter 9 3DGraphics ......................293
Primitives.............................293
Points..............................294
Lines..............................294
Triangles............................295
Indexed Geometry ......................297
ModelsandMeshes .......................299
XSIandXNA..........................300
LoadingandRenderingModels ...............302
3DModelsImplementation..................303
VirtualCameras .........................305
3DCameraImplementation .................307
Animations............................314
Straight-PathAnimationImplementation..........314
SkeletonAnimation......................322
3DShooterGameVersion1...................329
GameandMenuScreens...................332
ThePlayerandCamera....................333
Loading the Level and the Game...............341
Summary.............................355
Chapter 10 Importers/Converters .................357
StandardImportersandContentProcessors..........357
AutodeskFBX(.fbx)Importer................358
Effect(.fx)ImporterandProcessor.............358
ModelProcessor........................359
NoProcessingRequired ...................360
SpriteFontDescriptorImporterandProcessors......360
TextureImporterandProcessor...............360
XFileImporter........................361
XACTImporterandProcessor................361
XMLImporter.........................362
Contents
vi
ExtendingtheStandardContentProcessing..........362
A Simple Example of Extending a Standard Processor . . . 362
WritingaCustomImporterandProcessor...........366
CreatingtheImportersProject...............368
StoringImportedandCompiledData............370
CreatingtheImporter.....................370
CreatingtheProcessor....................371
CreatingtheContentWriter.................373
CreatingtheContentReader.................374
TestingtheCustomImporterinanApplication.......375
3DShooterGameVersion2...................377
GameEnemies ........................377
Version2oftheGame.....................382
AddingCustomContent ...................394
Summary.............................395
Chapter 11 ShadersandCustomEffects..............397
ShaderModels..........................399
ShaderModel1.0.......................399
ShaderModel2.0.......................400
ShaderModel3.0.......................401
ShaderModel4.0.......................402
VertexandPixelShaders ....................402
VertexShaders ........................403
PixelShaders.........................405
GeometryShaders ......................407
An Overview of the High-Level Shading Language (HLSL) . 408
DataTypesandSwizzling...................409
Semantics...........................412
Techniques and Passes ....................413
SimpleShaderDemo.......................414
Summary.............................421
Chapter 12 Game Distribution, the Creators Club, and the
Xbox360........................423
SharingYourGames.......................423
JoiningtheCreatorsClub....................424
SettingUpYourPCandXbox360forXNAGames ......425
ProgrammingConsiderationsfortheXbox360 ........428
SafeRegions..........................429
AspectRatio..........................430
Graphics, Input, Audio, and Storage Differences
betweenPlatforms ......................430
Graphics...........................430
Contents
vii

Get Essential XNA Game Studio 2.0 Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.