Be a Supporter!

Edits to post #25318800 by swishcheese

Back to Particles vs Display Objects

Edited at 2014-12-03 16:59:01

At 12/3/14 12:25 AM, Barzona wrote: I still don't know much about particle effects and how they are generated, but I do know they aren't the same thing as display objects.

Anything drawn to the the DisplayList in Flash is going to inherit the display object class. The idea of particles though, is that you have tons and tons of them. Having 100+ display objects and adding the to the display list is not that great of an idea.

instead, have a class that holds the information of a pixel (x and y position, color, size, opacity etc). Then you'll need a container that will hold a list of pixel. This class is then used to draw the pixels. This class should have an update method that modifies all the pixels in the list according to whatever rules you want to follow (say fading them away). In addition, should have a draw method that draws all the pixels. This update and draw method is then called every frame, or however you want to handle time.

Example:

public class Pixel
{
    public var pos:Point;
    public var color:UInt;
    public var size:Float;
    public var opacity:Float;
    
    public Pixel(p:Point, c:Uint, s:Float, o:Float)
    {
         pos = p;
         color = c;
         size = s;
         opacity = o;
     }

     public function update(deltaTime:Float, fps:Int) : void
     {
           //do update logic here (moving pixel, fading, etc)
           opacity -= 0.025 * (deltaTime / fps);
     }
}

//container class
public class PixelHandler extends Shape
{
     private var particles:Vector<Pixel>;
      
      public PixelHandler (numOfParticles:Int)
     {
          particles = new Vector<Pixel>();
          for(var i:Int = 0; i < numOfParticels; ++i)
          {
               particles.push( new Pixel ( randomPos, randomColor, 1));
           }
     }

     public function update(deltaTime:Float, fps:Int) : void
    {
          for(var i:int = 0; i < particles.length; ++i)
          {
               particles[i].update(deltaTime, fps);
           }
     }

     public function draw() : void
     {
          this.graphics.clear();
          for(var i:int = 0; i < particles.length; ++i)
          {
              this.graphics.beginFill(particles[i].color, particles[i].opacity);
              this.graphics.drawRect(particles[i].x, particles[i].y, particles[i].size, particles[i].size);
              this.graphics.endFill();
           }
     }
}

At 12/3/14 12:25 AM, Barzona wrote: I still don't know much about particle effects and how they are generated, but I do know they aren't the same thing as display objects.

Anything drawn to the the DisplayList in Flash is going to inherit the display object class. The idea of particles though, is that you have tons and tons of them. Having 100+ display objects and adding them to the display list is not that great of an idea.

instead, have a class that holds the information of a pixel (x and y position, color, size, opacity etc). Then you'll need a container that will hold a list of pixel. This class is then used to draw the pixels. This class should have an update method that modifies all the pixels in the list according to whatever rules you want to follow (say fading them away). In addition, should have a draw method that draws all the pixels. This update and draw method is then called every frame, or however you want to handle time.

Example:

public class Pixel
{
    public var pos:Point;
    public var color:UInt;
    public var size:Float;
    public var opacity:Float;
    
    public Pixel(p:Point, c:Uint, s:Float, o:Float)
    {
         pos = p;
         color = c;
         size = s;
         opacity = o;
     }

     public function update(deltaTime:Float, fps:Int) : void
     {
           //do update logic here (moving pixel, fading, etc)
           opacity -= 0.025 * (deltaTime / fps);
     }
}

//container class
public class PixelHandler extends Shape
{
     private var particles:Vector<Pixel>;
      
      public PixelHandler (numOfParticles:Int)
     {
          particles = new Vector<Pixel>();
          for(var i:Int = 0; i < numOfParticels; ++i)
          {
               particles.push( new Pixel ( randomPos, randomColor, 1));
           }
     }

     public function update(deltaTime:Float, fps:Int) : void
    {
          for(var i:int = 0; i < particles.length; ++i)
          {
               particles[i].update(deltaTime, fps);
           }
     }

     public function draw() : void
     {
          this.graphics.clear();
          for(var i:int = 0; i < particles.length; ++i)
          {
              this.graphics.beginFill(particles[i].color, particles[i].opacity);
              this.graphics.drawRect(particles[i].x, particles[i].y, particles[i].size, particles[i].size);
              this.graphics.endFill();
           }
     }
}

Edited at 2014-12-03 16:56:27

At 12/3/14 12:25 AM, Barzona wrote: I still don't know much about particle effects and how they are generated, but I do know they aren't the same thing as display objects.

Anything drawn to the the DisplayList in Flash is going to inherit the display object class. The idea of particles though, is that you have tons and tons of them. Having 100+ display objects and adding the to the display list is not that great of an idea.

instead, have a class that holds the information of a pixel (x and y position, color, size, opacity etc). Then you'll need a container that will hold a list of pixel. This class is then used to draw the pixels. This class should have an update method that modifies all the pixels in the list according to whatever rules you want to follow (say fading them away). In addition, should have a draw method that draws all the pixels. This update and draw method is then called every frame, or however you want to handle time.

Example:

public class Pixel
{
    public var pos:Point;
    public var color:UInt;
    public var size:Float;
    public var opacity:Float;
    
    public Pixel(p:Point, c:Uint, s:Float, o:Float)
    {
         pos = p;
         color = c;
         size = s;
         opacity = o;
     }

     public function update(deltaTime:Float, fps:Int) : void
     {
           //do update logic here (moving pixel, fading, etc)
           opacity -= 0.025 * (deltaTime / fps);
     }
}

//container class
public class PixelHandler extends Shape
{
      var particles:Vector<Pixel>;
      
      public PixelHandler (numOfParticles:Int)
     {
          particles = new Vector<Pixel>();
          for(var i:Int = 0; i < numOfParticels; ++i)
          {
               particles.push( new Pixel ( randomPos, randomColor, 1));
           }
     }

     public function update(deltaTime:Float, fps:Int) : void
    {
          for(var i:int = 0; i < particles.length; ++i)
          {
               particles[i].update(deltaTime, fps);
           }
     }

     public function draw() : void
     {
          this.graphics.clear();
          for(var i:int = 0; i < particles.length; ++i)
          {
              this.graphics.beginFill(particles[i].color, particles[i].opacity);
              this.graphics.drawRect(particles[i].x, particles[i].y, particles[i].size, particles[i].size);
              this.graphics.endFill();
           }
     }
}

At 12/3/14 12:25 AM, Barzona wrote: I still don't know much about particle effects and how they are generated, but I do know they aren't the same thing as display objects.

Anything drawn to the the DisplayList in Flash is going to inherit the display object class. The idea of particles though, is that you have tons and tons of them. Having 100+ display objects and adding the to the display list is not that great of an idea.

instead, have a class that holds the information of a pixel (x and y position, color, size, opacity etc). Then you'll need a container that will hold a list of pixel. This class is then used to draw the pixels. This class should have an update method that modifies all the pixels in the list according to whatever rules you want to follow (say fading them away). In addition, should have a draw method that draws all the pixels. This update and draw method is then called every frame, or however you want to handle time.

Example:

public class Pixel
{
    public var pos:Point;
    public var color:UInt;
    public var size:Float;
    public var opacity:Float;
    
    public Pixel(p:Point, c:Uint, s:Float, o:Float)
    {
         pos = p;
         color = c;
         size = s;
         opacity = o;
     }

     public function update(deltaTime:Float, fps:Int) : void
     {
           //do update logic here (moving pixel, fading, etc)
           opacity -= 0.025 * (deltaTime / fps);
     }
}

//container class
public class PixelHandler extends Shape
{
     private var particles:Vector<Pixel>;
      
      public PixelHandler (numOfParticles:Int)
     {
          particles = new Vector<Pixel>();
          for(var i:Int = 0; i < numOfParticels; ++i)
          {
               particles.push( new Pixel ( randomPos, randomColor, 1));
           }
     }

     public function update(deltaTime:Float, fps:Int) : void
    {
          for(var i:int = 0; i < particles.length; ++i)
          {
               particles[i].update(deltaTime, fps);
           }
     }

     public function draw() : void
     {
          this.graphics.clear();
          for(var i:int = 0; i < particles.length; ++i)
          {
              this.graphics.beginFill(particles[i].color, particles[i].opacity);
              this.graphics.drawRect(particles[i].x, particles[i].y, particles[i].size, particles[i].size);
              this.graphics.endFill();
           }
     }
}