University of Kentucky Engineering Day Windows Phone 7 Game Development using XNA Tamas Nagy Department of Computer Science University of Kentucky Saturday Feb. 25, 2011
Free Renegade 25.02.2012 Tamas Nagy Univ. of Kentucky 2
Overview Background Introduction to Game Programming Pitfalls Platforms Software Needed Introduction to SLXna and XNA Sample 2d game 25.02.2012 Tamas Nagy Univ. of Kentucky 3
Programmer Programmer (n) An organism that converts caffeine into code I tried to change the world, but I couldn t find the source code 25.02.2012 Tamas Nagy Univ. of Kentucky 4
So you want to make a game? You have many options. Platform Genre Graphics (2D vs 3D) Language Connectivity Choose your team wisely and draw up a contract for revenue at the start. It will avoid conflicts later. Be flexible and motivated. It will take a lot of willpower to finish a project this size. 25.02.2012 Tamas Nagy Univ. of Kentucky 5
Pitfalls Over complication Not using libraries Skipping on Design Phase Rigid code Not prototyping enough 25.02.2012 Tamas Nagy Univ. of Kentucky 6
Platform Which platforms to support? Xbox Windows Phone 7 Android ios Linux Windows, etc How difficult/time consuming will it be to deploy? 25.02.2012 Tamas Nagy Univ. of Kentucky 7
Windows Phone 7 as a Platform Robust and powerful OS based on Windows CE Kernel Lots of Incentives for students DreamSpark Microsoft-sponsored competitions Smaller market leads to more visibility Up and coming Shares most of codebase with Windows and Xbox so most tutorials are cross compatible 25.02.2012 Tamas Nagy Univ. of Kentucky 8
Software Needed Microsoft Visual Studio 2010 Express for Windows Phone 2D Graphical Software Inkscape 3D Graphical Software Wings3D MSDN Dev Net 25.02.2012 Tamas Nagy Univ. of Kentucky 9
Introduction to XNA and SLXna Silverlight XNA (WP7 7.1+ Mango ) Convenience Expression Blend Animations Application blends in with WP7 UI 25.02.2012 Tamas Nagy Univ. of Kentucky 10
Introduction to XNA and SLXna Pure XNA 4.0 Refresh (WP7 7.0+, Windows, Xbox) not used in combination with Silverlight Portability Compatibility Speed Resource amount 25.02.2012 Tamas Nagy Univ. of Kentucky 11
XNA and SLXna Games Have a set structure across all platforms (N/A to SLXna) Uses C# or VB C++ will be added with Apollo Convenience framework SpriteBatch Model, Mesh, etc Content Processing 25.02.2012 Tamas Nagy Univ. of Kentucky 12
Drawbacks to conventional XNA Complexity XNA/C# coding is much more complex than alternatives such as GameMaker. Overkill for simple 2D games Lack of in-game menu creation All of the menus have to created manually Difficult to make look nice at first Incompatibility with frameworks outside of.net 25.02.2012 Tamas Nagy Univ. of Kentucky 13
An example simple 2D game Features Game State Management Support for pause/resume etc Player controlled by accelerometer Tap to fire Random enemy spawning Rudimentary particle system http://msdn.microsoft.com/en-us/hh641313 25.02.2012 Tamas Nagy Univ. of Kentucky 14
Questions? 25.02.2012 Tamas Nagy Univ. of Kentucky 15
University of Kentucky Engineering Day High Performance Graphics using XNA (WP7/8, XBOX, Windows) Tamas Nagy Department of Computer Science University of Kentucky Saturday Feb. 25, 2011
Before we begin Premature optimization is the root of all evil -Donald Knuth XKCD: http://imgs.xkcd.com/comics/the_general_problem.png 25.02.2012 Tamas Nagy Univ. of Kentucky 17
High Performance Graphics (HPG) OpenGL Khronos Group Open-Source Low-level Platform-Independent Direct3D/DirectX & XNA Microsoft Closed-Source Direct3D low level, XNA high level Platform-Independent 25.02.2012 Tamas Nagy Univ. of Kentucky 18
Hardware Acceleration with HPG Utilizes power of the graphics card Hundreds of parallel processors Super-speed VRAM Dedicated FPUs, etc Many different companies/protocols Nvidia, AMD, ARM, Qualcomm, etc OpenGL 1.0-4.2, Direct3D 5-11.1, XNA 1.0-4.0R XNA abstracts all this away; no boilerplate code 25.02.2012 Tamas Nagy Univ. of Kentucky 19
3D Graphics The screen is still two dimensional but the game world itself has three dimensions. Two coordinate systems Left-handed (+z going into the screen) Right-handed (+ z coming out of screen) ß XNA default 25.02.2012 Tamas Nagy Univ. of Kentucky 20
Example graphics pipeline http://http.developer.nvidia.com/cgtutorial/cg_tutorial_chapter01.html http://what-when-how.com/wp-content/uploads/2011/08/ tmpd73_thumb1.jpg 25.02.2012 Tamas Nagy Univ. of Kentucky 21
Introduction to Primitives, Vertex Arrays and VBOs Primitives A basic building block for constructing complex 3D shapes LineList LineStrip TriangleList TriangleStrip Vertex Arrays vs. Vertex Buffer Objects http://what-when-how.com/xna-game-studio-4-0- programmingdeveloping-for-windows-phone-7-and-xbox-360/let-the-3drendering-start-xna-game-studio-4-0-programming-part-1/ http://what-when-how.com/wp-content/uploads/2011/08/tmpd81_thumb.jpg http://what-when-how.com/wp-content/uploads/2011/08/tmpd96_thumb2.jpg 25.02.2012 Tamas Nagy Univ. of Kentucky 22
Complex 3D Objects Represents as Models in XNA Examples An animal A car An entire level Made up of ModelMeshes that represent a single physical object Examples A door Tires Has a ModelMeshPart that contains all same material triangles Reflective for car windows Shiny for car hood ModelBone How the ModelMesh is positioned relative to the rest of the object 25.02.2012 Tamas Nagy Univ. of Kentucky 23
Content Processing Allows you to precompile all of your resources into a binary format (.xnb) so that you will not have to do it at runtime Custom Content Processors are easy to write Easy level creation via XML 25.02.2012 Tamas Nagy Univ. of Kentucky 24
State machines Graphics card are state machines Excellent at performing same operations many times. State changes are expensive PCI-E (and equivalent) interfaces are slow 25.02.2012 Tamas Nagy Univ. of Kentucky 25
A Performance Detour Do not be misled by the functions; the GPU will be rendering while the CPU is running your update and render functions. CPU-bound vs GPU-bound Miller et al. XNA Game Studio 4.0 Programming 25.02.2012 Tamas Nagy Univ. of Kentucky 26
Object Pooling Essential for games written in a managed language Basically, keeping references to all game objects so that none of them are deallocated into the heap. Artifacts Full reset required otherwise an object might retain qualities across instances 25.02.2012 Tamas Nagy Univ. of Kentucky 27
Questions? 25.02.2012 Tamas Nagy Univ. of Kentucky 28