XNA Level 1 Lesson 1
XNA Lessons Level 1 – A Basic Game
Lesson 1 - Creating a new Project
Open Visual C# and create a new project
Choose ‘Windows Game 4.0’ and call it Lesson01
Press F5 to run your game you should see the following screen
Note: If you see the following warning you maybe on laptop or other low powered machine you may have to make the following change.
Project --> Properties
Select the ‘use reach’ button
Exploring the project
Now that you have created you first project, lets familiarise ourselves with the layout
The game contains the following functions
Game1() Is what starts the game running
Initialise() is where we can create new things when the program first starts
LoadContent() as it sounds, this is where we can load our things.
Update() is where we move our characters
Draw() go on.. take a guess :)
The Code should look like this, I have removed all the comment code to make it easier to read
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
}
protected override void UnloadContent()
{
}
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 here
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
//GraphicsDevice.Clear(Color.CornflowerBlue);
GraphicsDevice.Clear(Color.Black);
// TODO: Add your drawing code here
base.Draw(gameTime);
}
}
Make sure your are familiar with the layout of the code, where each function is.
Changing the Background Colour
In the ‘Draw’ function change the line from Color.CornflowerBlue to Color.Black, so it should look something like this
protected override void Draw(GameTime gameTime)
{
//GraphicsDevice.Clear(Color.CornflowerBlue);
GraphicsDevice.Clear(Color.Black);
// TODO: Add your drawing code here
base.Draw(gameTime);
}
Press ‘F5’ and you should get the following
Feel free to try different colours (colors)
Well Done. NEXT>>
|