Skip to Main Content
Learning XNA 3.0
book

Learning XNA 3.0

by Aaron Reed
November 2008
Beginner content levelBeginner
510 pages
16h 24m
English
O'Reilly Media, Inc.
Content preview from Learning XNA 3.0

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; ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning XNA 4.0

Learning XNA 4.0

Aaron Reed
Beginning C# 7 Programming with Visual Studio 2017

Beginning C# 7 Programming with Visual Studio 2017

Benjamin Perkins, Jacob Vibe Hammer, Jon D. Reid

Publisher Resources

ISBN: 9780596154905Supplemental ContentErrata Page