DOC PREVIEW
GT ECE 4893 - Walkthrough of an XNA 2D Game
School name Georgia Tech
Pages 43

This preview shows page 1-2-3-20-21-22-41-42-43 out of 43 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 43 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 43 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 43 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 43 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 43 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 43 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 43 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 43 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 43 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 43 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Walkthrough of an XNA 2D Game Prof. Aaron Lanterman (Based on slides by Prof. Hsien-Hsin Sean Lee) School of Electrical and Computer Engineering Georgia Institute of Technology2D games • Using “Sprites” – All textures – Simple to make or obtain • Early games before the 3D revolution – Space Invaders, Lode Runner, Donkey Kong, Pac-Man • Do not require high performance accelerators • Simple enough for your grandparents to enjoy • Easy to do using XNA framework • No “effect” (.fx) usedProf. Lee’s game: DawgShower • Shoot the bad dawgs! • Consist of four main objects – The shooter (ship.cs) – The bad dawgs (meteros.cs) – The missile (missile.cs) – Music (AudioComponent.cs) • The moving objects are all made of sprites Adapted from Chapter 3 of A. Lobao, B. Evangelista, and J.A. Leal de Farias, “XNA 2.0 Game Programming: From Novice to Professional”ScreenshotDemo DawgShower Game ExampleTop level program (Program.cs)Main game loop (Game1.cs)Add Game ComponentAdding Game Component (C# src file) • Adding new DrawableGameComponent class of objects in the game – This class loads and draws graphics content • Project  Add ComponentsDrawableGameComponent class (1)DrawableGameComponent class (2) • Inherits: – GameComponent.Initialize – GameComponent.Update – DrawableGameComponent.Draw • Base.draw() method will go through all DrawableGameComponents to execute their respective draw() callMain program in Game1.cs My codeFull screen modeDrawing sprites using XNA • Use “textures” • Store with XNA’s Texture2D class • Include new texture images into the Content Pipeline • Use “Content.Load” to associate texture variablesBig sprites for the backgroundSmall sprites for game assetsGame Services • Game services maintain loose coupling between objects that need to interact with each other • Register a “global” SpriteBatch for drawing all sprites • Draw() method will look for an active SpriteBatch in GameServices • All GameComponents will use this SpriteBatchGame Services – setup & use Registering a Game Service in LoadContent() Use GetService to acquire service for each DrawableGameComponentDrawing the background Draw other spritesPrinting text • Draw using SpriteBatch • Create a “font sprite” • Based on available Fonts in the system • Add font in LoadContent()Create a SpriteFont (1)Create a SpriteFont (2)DrawStringManage components • Components: member of GameComponentCollection (i.e., Microsoft.XNA.Framework.Game) • Use Components.Add() to add a new component to the list • Components.RemoveAt(j) removes jth componentAdd sound and the player’s shipAdd missiles, remove meteorsGame logic • Embedded inside Update() functionPause the gameBuilt-in test for collision detection • Test bounding boxes of given rectangular sprites • Return a Boolean result Missile’s positionBoundingSphere • Alternative method (more often used for 3-D games)Sound – simple, easy way (1) • Can use .wav, .mp3, and .wma • SoundEffect Class – Quick vocalizations, door knocks, etc. • Song Class – Background music • MediaPlayer Class – Can pause, resume, skip around, change volume, etc. – Access user’s music library on WMP, Xbox 360, and ZuneSound – simple, easy way (2) • Drag sound files into Content folder • Load through Content Pipeline SoundEffect soundEffect = ! Content.Load<SoundEffect>(@"Content\Audio\LaserShot");!"!soundEffect.Play();!Example from http://xna-uk.net/blogs/offbyone/archive/2010/01/21/sound-in-xna-3-1-part-i.aspxSound – powerful, complex way • XACT: Microsoft Cross-Platform Audio Creation Tool • Only way to do sound before XNA 3.0!Using XACT • Create wave banks and sound banks • Compile them into XAP file used by the content manager “checked” for looping background music Copy and make sound cues by dragging the files into this windowUsing files created by XACT in XNA • Create a new GameComponent for audio • Initialize WaveBank and SoundBank in the C# code This “Content” directory is located in <Proj>/bin/x86/<Sln Config>/Content AudioEngine object is the program reference to the audio services in your machine provided by XNAXACT – background looping music • Add in Initialize code of the Game • PlayCue is a method of SoundBankXACT – play sound on event • Shoot.wav in SoundBank was not set to “infinite”, thus will only be played onceGame Over • Remove all components • Replace background canvas • Pause the musicGame Over - CodeOrganized game structure SoundBank Play Again?Class GameScene : DrawableGameComponent PlayScene Play


View Full Document

GT ECE 4893 - Walkthrough of an XNA 2D Game

Documents in this Course
Load more
Download Walkthrough of an XNA 2D Game
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Walkthrough of an XNA 2D Game and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Walkthrough of an XNA 2D Game 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?