Chapter 3. Fun with Sprites
In the previous chapter, I mentioned that there was actually a lot happening behind the scenes of the simple blue-screen game you built. Let’s take a more in-depth look at that code and see what’s actually going on. To start, open the game project that you created in Chapter 2.
A Look Behind the Scenes
The program.cs file
is pretty straightforward. Your Main
method, which creates a new object of type Game1
and executes its Run
method, is located in this file.
The real guts of your game lie in the Game1.cs file. The code for that file will look something like this:
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; namespace Collision { /// <summary> /// This is the main type for your game /// </summary> public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; } /// <summary> /// Allows the game to perform any initialization it needs to before /// starting to run. This is where it can query for any required /// services and load any non-graphic-related content. Calling /// base.Initialize will enumerate through any components /// and ...
Get Learning XNA 4.0 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.