Fun Infused Games  |   Smooth Operator

  Home   |    Archive   |    About
Posts prior to 8/2/2010 may be missing data. If you need one of those posts, please contact kriswd40@yahoo.com and I will try and recover/find it.

A Better Particle Effects Object
Date 3/13/2010    Tags XNA    (0)



Believe it or don't, the orange things are the explosion. Much like hockey, it's better live.
One year and one day ago, I wrote the widely popular article A Simple Particle Effects Object. Since that time, I've used this object in two different games and have modified it to be slightly better.

The improvements to this object include:
  • Particles fade to transparent.
  • Easier to implement different types of particles.
  • Ability to spread particles out rather than having them all generate from the exact same point (SpreadXDistance, SpreadYDistance).
In order to use this object, you will need to add Particle and Particles classes to your project. Particle is an individual particle and all associated properties / methods. Particles is a collection of Particle objects along with methods to create, draw, update, and fire your Particle objects.

I have included one example particle in the Particle class (Orange)... you can create new ones by adding a value to the ParticleType enum and then setting the properties for that ParticleType in the Particle constructor.

public class Particle
{
    private Texture2D particleTexture;

    public enum ParticleType
    {
        Orange = 1
    }

    public Vector2 Position
    {
        get;
        set;
    }

    public Vector2 Direction
    {
        get;
        set;
    }

    public Vector2 Speed
    {
        get;
        set;
    }

    public int SpreadXDistance
    {
        get;
        set;
    }

    public int SpreadYDistance
    {
        get;
        set;
    }

    public ParticleType currentParticleType
    {
        get;
        set;
    }

    // The most opaque a particle can be.
    public float MaxAlphaAmount
    {
        get;
        set;
    }

    public int Width
    {
        get;
        set;
    }

    public int Height
    {
        get;
        set;
    }

    public bool Active
    {
        get;
        set;
    }

    public float ParticleTimerStartValue
    {
        get;
        set;
    }

    public Particle(ParticleType initialParticleType, ContentManager contentManager)
    {
        currentParticleType = initialParticleType;
        this.SpreadXDistance = 0;
        this.SpreadYDistance = 0;
        this.Active = false;

        switch (currentParticleType)
        {
            case ParticleType.Orange:
            {
                Speed = new Vector2(350, 350);
                Direction = new Vector2(0, 0);
                particleTexture = contentManager.Load<Texture2D>("Particles\\Orange");
                this.ParticleTimerStartValue = .5f;
                this.SpreadXDistance = 15;
                
                    

This article has been view 2847 times.


Comments

No comments for this article.


Add Comments

Name *
Website
  Name the animal in the picture below:

*  
Comment *
Insert Cancel
Things To Click


Tags
Video Games (7)  Trivia or Die (3)  SQL (1)  iOS (3)  Game Dev (11)  Advise (14)  PC (1)  World of Chalk (2)  FIN (20)  Abduction Action! (27)  XBLIG (32)  Abduction Action (1)  Nastier (4)  ASP.net (18)  Absurd (2)  Volchaos (11)  Web (19)  Fin (1)  XNA (40)  Rant (50)  Cool (2)  Visual Studio (1)  Trivia Or Die (1)  Xbox (1)  C# (14)  Sports (11)  Design (2)  Development (13)  Hypership (28)  WP7 (8)  VolChaos (1)  Nasty (34)  Abdction Action! (1)