<< Chapter < Page | Chapter >> Page > |
Revised: Sun May 08 09:19:08 CDT 2016
This page is part of a Book titled XNA Game Studio .
This module is one in a collection of modules designed primarily for teaching GAME 1343 Game and Simulation Programming I at Austin Community College in Austin, TX. These modules are intended tosupplement and not to replace the textbook.
An earlier module titled Getting Started provided information on how to get started programming with Microsoft's XNA Game Studio.
I recommend that you open another copy of this module in a separate browser window and use the following links to easily find and view the Figuresand Listings while you are reading about them.
The earlier module titled Xna0118-The XNA Framework and the Game Class used a very simple XNA program to teach many of the details regarding the incorporation ofthe XNA framework into the object-oriented C# programming language.
When you create a new Windows Game project using Visual C#, a source code file named Game1.cs is automatically created and opened in the editor window. The file contains skeleton code for a windows gamebased on XNA. Listing 1 shows the skeleton code contained in the file named Game1 (with most of the comments deleted for brevity).
Listing 1 . Skeleton code for a new Windows Game project.
using System;
using System.Collections.Generic;using System.Linq;
using Microsoft.Xna.Framework;using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;namespace WindowsGame2
{public class Game1 : Microsoft.Xna.Framework.Game
{GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;public Game1()
{graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";}
protected override void Initialize(){
// TODO: Add your initialization logic herebase.Initialize();
}protected override void LoadContent()
{// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);// TODO: use this.Content to load your game content here
}protected override void UnloadContent()
{// TODO: Unload any non ContentManager content here
}protected override void Update(GameTime gameTime)
{// Allows the game to exit
if(GamePad.GetState(PlayerIndex.One).Buttons.Back==ButtonState.Pressed)this.Exit();
// TODO: Add your update logic herebase.Update(gameTime);
}protected override void Draw(GameTime gameTime)
{GraphicsDevice.Clear(Color.CornflowerBlue);
// TODO: Add your drawing code herebase.Draw(gameTime);
}}
}
Notification Switch
Would you like to follow the 'Xna game studio' conversation and receive update notifications?