O'Reilly logo

Learning XNA 3.0 by Aaron Reed

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding a Starfield

Given the way that you've created your particles and your particle engine, you're perfectly set up for creating a field of stars in the background to make this look more like outer space. To do this, you'll need to create a new version of your ParticleExplosion class that treats the particles a little bit differently. For example, the particles you use for stars in the background won't move around the screen the way the ones in the explosions do. You also won't be deleting stars from the list of stars to draw, nor will your star particle engine die out at some time—the stars will be the same at the end of the game as they were at the beginning.

Add a new class to your project by right-clicking the solution and selecting Add → Class.... Name the class ParticleStarSheet:

Replace the code in the file that is generated with the following: using System; using System.Collections.Generic; using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; namespace _3D_Game { class ParticleStarSheet { //Particles Particle[] particles; //Behavior variables Vector3 maxPosition; int maxParticles; Vector2 textureSize; static Random rnd = new Random(); //Graphics related variables VertexDeclaration vertexDeclaration; GraphicsDevice graphicsDevice; ParticleSettings particleSettings; public ParticleStarSheet(GraphicsDevice graphicsDevice, Vector3 maxPosition, int maxParticles, Vector2 textureSize, ParticleSettings particleSettings) { this.maxPosition = maxPosition; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required