Time for action – spark effects

  1. Add the AddSparkEffect() method to the "Public Methods" region of the EffectsManager class:
    public static void AddSparksEffect(
        Vector2 location, 
        Vector2 impactVelocity)
    {
        int particleCount = rand.Next(10, 20);
        for (int x = 0; x < particleCount; x++)
        {
            Particle particle = new Particle(
                location - (impactVelocity / 60),
                Texture,
                ParticleFrame,
                randomDirection((float)rand.Next(10, 20)),
                Vector2.Zero,
                60,
                20,
                Color.Yellow,
                Color.Orange);
            Effects.Add(particle);
        }
    }
  2. In the LoadContent() method of the Game1 class, initialize the EffectsManager after the Player class has been initialized:
    EffectsManager.Initialize(
        spriteSheet,
        new Rectangle(0, 288, 2, 2),
        new Rectangle(0, 256, 32, 32),
        3);
  3. In the Update() method of the Game1 ...

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.