90 likes | 243 Views
XNA. Briana B. Morrison CSE 1302C Spring 2010. Topics. Games in XNA Structure of programs Purpose of methods Example. Games in XNA. Create a game project Shell is created for you Extensive libraries. Structure of Programs.
E N D
XNA Briana B. Morrison CSE 1302C Spring 2010
Topics Games in XNA Structure of programs Purpose of methods Example
Games in XNA • Create a game project • Shell is created for you • Extensive libraries
Structure of Programs • Solution.sln - this is the solution file of the entire project. • Solution.suo - this is data file that XNA GS uses. We will not change this file. • Game1.cs - This file contains the Game1 class. This is the main file we will work with. • Game1.ico - This is the graphical icon on the title bar of the running program. • GameThumbnail.png - This is the graphical file for representing this game on the XBOX 360 console. • Program.cs - This is the container class of the Game1 class. • Solution.csproj - This is the project description file for the .slnsolution file. • bin and obj - Compile result. As the names suggests, objcontains the compile object files, while bin contains the executable binary files. • Properties/AssemblyInfo.cs - Description for the project, e.g., name to appear on the window title bar. • Content/Content.contentproj - This is the content project description file. Fonts, file texture images, and audio wave files are examples of contents. • Content/bin and obj - Build results from the content project.
Methods Program.cs • container class for the Game1.cs class • Creates instance of Game1 and runs Game1.cs: this is the source code we will work with. Notice there are six functions: • Game1( ): this is the constructor. • Initialize( ): initialize the application state. • LoadContent( ): load contents (e.g., audio file, file texture images, and fonts). • UnloadContent( ): Unload contents as the application exists. • Update( ): updates the application's state • Draw( ): draws the application's state
To Create Your Game Most notably, you need to handle: • Constructor - initialize and set up variables as usual • LoadContent - load SpriteFont, Texture2D, etc. • Update - handle all user input and update game state • Draw - handle drawing the images/graphics to the screen • Note that NO drawing should happen in Update, and no input/state changes should happen in Draw.
Things to Remember • Draw your assets (using transparent backgrounds if desired) in your favorite paint program. GIMP and Paint.NET are both free • Add your assets to the Content folder and then add them to your project (via "Project | Add | Add Existing...") • Create attributes within the class to hold the assets • Load the assets into the attributes in the LoadContent method • Handle user input (via the GetState method of the Keyboard class) • Draw icons/sprites to the screen (via the Draw method of the SpriteBatch class) • Draw strings to the screen (via the DrawString method of the SpriteBatch class) • Be sure to place all screen manipulation inside the Begin/End methods of the SpriteBatch class • Generate random values via the Next method of the Random class • List<> is a parameterized collection class that is useful for storing dynamic collections of items; use the Add, Remove, RemoveAt, etc. methods
More information • Detailed steps in 7 audio/video tutorials on course website under Announcements