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 Your Particle Engine to Your Game

Now that you have an effect and a particle engine, you need to modify your code to create explosions when ships are hit.

The first thing that you'll need to do is add the texture image for the particles to use. This texture will give the particles their color—every particle will be assigned a random pixel from the texture and will be given the color at that pixel in the texture.

If you haven't already, download the source code for this chapter of the book. In the 3D Game\Content\Textures folder, you'll find an image file called Particle.png. Add it to your project by right-clicking the Content\Textures folder in Solution Explorer, selecting Add → Existing Item..., and then navigating to the Particle.png file and selecting it.

Now open the ModelManager class, and let's get to work on adding some cool explosions to your game. Add the following class-level variables:

List<ParticleExplosion> explosions = new List<ParticleExplosion>(  );
ParticleExplosionSettings particleExplosionSettings =
    new ParticleExplosionSettings(  );
ParticleSettings particleSettings = new ParticleSettings(  );
Effect explosionEffect;
Texture2D explosionTexture;

These variables are all pretty self-explanatory: you have a list of ParticleExplosions so your class can update and draw them, an instance of both settings classes for your particles, and Effect and Texture2D objects for drawing your particles.

Next, you'll need to load the resources for your particles, set the current ...

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