Fun Infused Games  |   Smooth Operator RSS 

  Home   |    Archive   |    Subscribe   |    Search   |    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


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