Creating Games For Windows, Xbox 360, and Windows Phone 7 Ryan Plemons http://digitaltransfusion.net @ryanplemons Where to begin? All demos in this slide deck are built with XNA 4. To follow along, you will need the following: Windows 7 or Vista A DirectX 9.1c capable graphic card (or better) with up to date drivers and DirectX runtime. If you’d like to debug Windows Phone 7 XNA projects you need a DirectX 10 capable graphic card (or better). Windows Phone 7 Development Tools XNA 4 is part of this package, and will install VS2010 Express. If you use a better version of VS2010, then the templates are installed for it as well. This will install an emulator for WP7 development What is XNA? XNA = XNA's Not Acronymed XNA is a powerful .Net API that handles graphics, sounds, inputs, networking, and storage that targets multiple platforms within the Microsoft envrionment. Windows Windows Phone 7 Xbox 360 Zune (and more to come)… Can I get an upgrade? If you are a student you can take advangate of the Dreamspark program. You can get a copy of: Windows 7/Vista Visual Studio 2010 Professional Expression Studio 4 Ultimate (and much, much more) Demo: Creating your first projects So what are these projects? There are 2 types of projects that are created out of the box. The main project targeting your platform This is the starting point of your application. You load assemblies, load media, move objects from here. A content project This is where you put all of your assets. XNA supports the following formats out of the box, but you can build other format importers. 2D graphics: .bmp, .png, .jpg 3D models: .x, .fbx Shaders: .fx Audio: .mp3, .wav, .wma WP7 requires PCM 16 bit mono/stero Video: .wmv Fonts: Any TrueType font XNA provides a set of sample high quality fonts (Andy Regular, Kootenay, Lindsey, etc) more info can be found here Any XML, text or binary files XNA for windows can skip this if you want, but it is required for Xbox and WP7. Demo: Adding assets to our game Basic Game Structure Initalize: called after the constructor. This is where you configure all your default values. Load Content: Called after Initialize, you load all assets for your game in here. Update: This is where you update data, look for keyboard input, do collision detection, etc. Draw: This is where you render your scene. Unload Content: Once the game exits, this is where any cleanup would happen. Basic Game Structure (cont) What is the GraphicsDeviceManager? This is the “graphical context” and is responsible for things like screen resolution, vertical synchronization, and antialiasing. It also gives you information on hardware capabilities. What is a SpriteBatch? Simply put, this is what allows you to “draw” 2d images to the screen. You can draw an entire image to the screen, or only a small part of the image to a specific area. There are no simple polygon “draw” methods. Everything is handled through textures. Consistency is the key! Speeds can vary from computer to computer, or device to device. XNA runs at 60 FPS by default. Can be adjusted IsFixedTimeStep (Bool) TargetElapsedTime (TimeSpan) Use gameTime.ElapsedGameTime to adjust for drift SpriteBatch Begin Tells GPU to draw everything coming to it, in the order you send it. Draw 0,0 is the top left Draw as many textures as possible in each SpriteBatch to keep speed up End Do this when done drawing, or when you need to change drawing settings. (such as AlphaBlend) Write once, Tweak for platform Windows Resolution can vary Mouse/Keyboard Input Xbox (640 x 480, 1280 x 720, 1920 x 1080) Controllers WP7 480 x 800, 320 x 480 Touch Screen EXTREME memory restrictions. What’s that? I can’t hear you! SoundEffect quick sound effects Background music loop sound.Play(); Used for quick audio. sound.CreateInstance(); Used for background music loops (allows pausing, volume adjustments on the fly, etc) Demo: Add the Background Add Paddles Add Ball Add Score Overlay Add Input Let’s get that ball rolling Ball starts in random direction +/- X +/- Y Starts at Width/2, Height/2 Change X or Y depending on collision Y changes based on collision with top or bottom X changes based on collision with paddle If X < 0 or X > width, then a point is awarded to the other side Demo: Animate ball Collision detection Bounding Box is top left Because this is a simple demo, I am using a rectangular bounding box for collision detection. You should do more fine grained collision detection for the real deal. Building for Xbox Create new project, copy csproj and rename Include in project “add” appropriate files Need creators club account Download Xbox Connect app to connect computer to Xbox for deployment Building for WP7 Create new project, copy csproj and rename Include in project “add” appropriate files Need windows phone developer account Don’t forget to turn off services Game hub or app hub? Further Concerns WP7 Multi-Touch input Accelerometer GPS Higher Resolution, Smaller Screen Tombstoning Ram Issues Applications can use (at most) 90MB of ram on a device with 256MB of ram. (lowest spec allowed) If a device has more than 256MB of ram you may use more than 90MB of ram to the amount of MemorySize – 256MB. If my device has 512MB of ram, I am allowed to use 512-256 + 90 = 346MB of ram Xbox: Development requires an Xbox for testing (no emulator) Q&A What questions do you have? Ryan Plemons http://digitaltransfusion.net @ryanplemons