| 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; |
| using Microsoft.Xna.Framework.Net; |
| using Microsoft.Xna.Framework.Storage; |
| |
| //lets take a run through of this code. just read the comments! |
| |
| namespace EmptyProjectCodeOverView |
| { |
| |
| public class Game1 : Microsoft.Xna.Framework.Game |
| { |
| |
| //right here we have the start of our game class ( defaulted to Game1 ) |
| |
| //this is a good place for adding your global variables |
| |
| // i usually make an area here for my variables in between comments like this |
| |
| //--------------------------------------- |
| GraphicsDeviceManager graphics; |
| SpriteBatch spriteBatch; |
| |
| // other variables here |
| //--------------------------------------- |
| |
| //lets move on |
| |
| |
| public Game1() //this is the constructor for our default Game1 class |
| { |
| graphics = new GraphicsDeviceManager(this); |
| Content.RootDirectory = "Content"; |
| |
| //it is mainly used for one time program wide initializations like running the game in full screen mode |
| |
| //like this |
| graphics.IsFullScreen = true; |
| |
| //that would run once when the program started and set the program to fullscreen mode |
| } |
| |
| |
| protected override void Initialize() //initialize: this function is used to initialize your variables. the ones that we put in the commented region at the start of the class. |
| { |
| base.Initialize(); |
| |
| |
| MyVariable = new MyVariable( so_on_so_forth ); |
| } |
| |
| |
| protected override void LoadContent() //load content does exactly name says it does this will load the content that you have declared in the variables section |
| //and it also sets up the SpriteBatch which is used for drawing sprites. which we will cover later |
| { |
| spriteBatch = new SpriteBatch(GraphicsDevice); |
| |
| |
| } |
| |
| |
| protected override void UnloadContent() |
| { |
| //this is used for getting rid of your content when the game exits. |
| //we will discuss this more later |
| } |
| |
| |
| protected override void Update(GameTime gameTime) //update. this is one of the core functions of the game. |
| { |
| |
| if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) |
| this.Exit(); |
| |
| |
| |
| //this function is ran many times per second. and is where alot of your core game logic will go. for exampe if you wanted to have a sprite move right. |
| //that would be done in this function. you would use something like |
| |
| |
| SpritePosition.X += speed; |
| |
| //the above code will add the variable 'speed' ( assuming you have created one ) and add it's value to the X coordinate of the variable SpritePosition.X ( assuming there is a variable called SpritePosition ) |
| |
| |
| base.Update(gameTime); |
| } |
| |
| |
| |
| protected override void Draw(GameTime gameTime) |
| { |
| GraphicsDevice.Clear(Color.CornflowerBlue); |
| |
| |
| //and finally this is where you put all of the code to draw things. whether is be models, sprites, text or anything else. it will go in here |
| |
| |
| base.Draw(gameTime); |
| } |
| } |
| } |
I hope this helps people get more familiar with XNA. next lesson i will cover some of the really useful classes and data types of XNA |