Time for action – updating and drawing explosions

  1. Add the Update() method to the ExplosionManager class:
    public void Update(GameTime gameTime)
    {
        for (int x = ExplosionParticles.Count-1; x >= 0; x--)
        {
            if (ExplosionParticles[x].IsActive)
            {
                ExplosionParticles[x].Update(gameTime);
            }
            else
            {
                ExplosionParticles.RemoveAt(x);
            }
        }
    }
  2. Add the Draw() method to the ExplosionManager class:
    public void Draw(SpriteBatch spriteBatch)
    {
        foreach (Particle particle in ExplosionParticles)
        {
            particle.Draw(spriteBatch);
        }
    }
  3. Add an instance of the ExplosionManager to the declarations area of the Game1.cs class file:
    ExplosionManager explosionManager;
  4. Still in the Game1 class, add the initialization of the explosionManager object to the LoadContent() method:
    explosionManager ...

Get XNA 4.0 Game Development by Example Beginner's Guide 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.