Game Programming Class1

esse quam videri
Revision as of 03:20, 4 September 2013 by Jeff (talk | contribs) (Jeff moved page XNA Programming Class1 to Game Programming Class1)
Jump to: navigation, search

Discuss Syllabus


What is XNA?


XNA Overview

Why do we need it?

Why not use c++?

Major changes in XNA 4

Mono Game

What is DirectX?

show c++ examples

quick start guide - create

Hello World

Hello World in XNA 4.0 using spritefont. We'll revisit the spriteFont when we build the console/debug class

Hello XNA with texture

Simple xna project that draws a pacman sprite

  • Start a new XNA Project

Add two variable declarations at the top of the class <csharp>

           Texture2D PacMan;
           Vector2 PacManLoc;

</csharp> In the LoadContent Function add the following code to initialize the two variables declared above <csharp>

       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
           //load PacMan image
           PacMan = Content.Load<texture2d>("pacmanSingle");
           //Center PacMan image
           PacManLoc = new Vector2(graphics.GraphicsDevice.Viewport.Width / 2, graphics.GraphicsDevice.Viewport.Height / 2);


  • Add the following code to the Draw Method to Draw the texture

<csharp> protected override void Draw(GameTime gameTime)

           // TODO: Add your drawing code here
           spriteBatch.Draw(PacMan, PacManLoc, Color.White);

</csharp> pacman image is availble here: PacmanSingle.png

the full game1.cs file should look like

[ IntroSimpleSpriteWindows/Game1.cs]

the build of the game will look like IntroSimpleSpriteWindows.png

Simple 2D texture example with update


Install VS2010 get XNA 4

Create an XNA Picture. The picture needs to have at least

  • 1 SpriteFont
  • 3 Textures

Also please post a screen shot of your project running in the assignments. Zip and upload source to moodle.

You can take a screen shot using the snip tool. Start run snip in vista or 7. Or you can just press the Print Screen key on the keyboard.