Game Programming Class2

esse quam videri
Revision as of 21:50, 2 February 2009 by Akelly (talk | contribs) (Texture2D and SpriteBatches)
Jump to: navigation, search


free game fonts XNA Redistributable Font Pack

Fun with Fonts in XNA

in class

Spritefont demo


XNA Structures

Game Class

The XNA Game class has two private properties

  • GraphicsDeviceManager graphics;
  • ContentManager content;
//the game constuctor can be used to set some graphics settings.
graphics.PreferredBackBufferHeight = 768;
graphics.PreferredBackBufferWidth = 1024;
//graphics.PreferredBackBufferHeight = 1080;
//graphics.PreferredBackBufferWidth = 1920;
//graphics.IsFullScreen = true;

  1. Declare SpriteBatch spriteBatch;
  2. Initialize()
  3. LoadContent()
  4. UnloadContent()
  5. Update(GameTime gameTime)


FrameRate and GameTime

Time and Timespan

Example of update using GameTime to calculate elapsed time

  • IntroSimpleSpriteWindows/Game1.cs

Understanding GameTime We'll revisit game time when we talk about performance profiling.

  1. Draw(GameTime gameTime)

Console And Trace

We will build a console class later and debug in game.

Texture2D and SpriteBatches

2D Graphics Overview

About textures and Batching

Displays, ViewPorts, Client Bounds

Alpha channels



demo project




  1. Options SpriteBlendMode
  2. Additive Enable additive blending.
  3. AlphaBlend Enable alpha blending.
  4. None No blending specified.

Other Projects


  • XNA Picture With Update
Update you picture to include some movement with the update method.
  • Sprite Class
Build a class that is reusable that can draw a single texture on the screen. Be sure to encapsulate all the properties and method that you need to draw the sprite.
  • Read Chapter 2 in XNA 3.0
  • Read Chapter 4 in XNA 3.0 (yes we skipped 3 we'll come back)