Difference between revisions of "Game Programming Class1"

esse quam videri
Jump to: navigation, search
(Hello World)
(What is XNA?)
Line 11: Line 11:
  
 
Why not use c++?
 
Why not use c++?
           
+
 
 +
Major changes in XNA 4
 +
* What's new http://msdn.microsoft.com/en-us/library/bb417503.aspx
 +
* Graphics Profiles
 +
**Reach HLSL 2.0
 +
**HiDef HLSL 3.0 platform showcase features
 +
 
 
==What is DirectX?==
 
==What is DirectX?==
 
show c++ examples
 
show c++ examples

Revision as of 20:45, 23 January 2011

Discuss Syllabus

Software

What is XNA?

Discussion
Why do we need it?

Why not use c++?

Major changes in XNA 4

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

Simple 2D texture demo

Simple xna project that draws a pacman sprite

  • Start a new XNA Project

Add two variable declarations at the top of the class

            Texture2D PacMan;
            Vector2 PacManLoc;

In the LoadContent Function add the following code to initialize the two variables declared above

        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
            PacMan = Content.Load<texture2d>("pacmanSingle");
            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
	protected override void Draw(GameTime gameTime)
        {
            graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

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

            base.Draw(gameTime);
        }

pacman image is availble here: PacmanSingle.png


the full game1.cs file should look like

[http://brookfield.rice.iit.edu/jmeyers/gbrowser.php?file=/ITM496-595/ClassSource/Projects/IntroSimpleSpriteWindows/IntroSimpleSpriteWindows/Game1.cs IntroSimpleSpriteWindows/Game1.cs]

the build of the game will look like IntroSimpleSpriteWindows.png


Simple 2D texture example with update

HomeWork

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

  • 1 SpriteFont
  • 3 Textures

Make a folder in your pub called XNA. Create an index for this folder and link the zipped VS2008 project here. Also please post a screen shot of your project running.

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

  • Read Chapter 1 of XNA 3.0
  • Listen to .NET rocks XNA podcast

http://www.dotnetrocks.com/default.aspx?showNum=501

subscribe to .NET rocks podcast