Okay, so I’ve been using particles for a long time and usually I just forgot to add them to the world or something stupid like that, but now I know to use them.
I have some boxes that emit particles, depending on the type of box they emit a different color. But I’m using one class to handle all of the particles.
Here is the code in the game world:
(under override public function begin())
GV.BOX_EMITTER = new Box_Trail;
add(GV.BOX_EMITTER );
In GV:
public static var BOX_EMITTER = new Box_Trail;
In the class box_trail:
public class Coin_Collect_Trail extends Entity
{
private var _emitter:Emitter;
[Embed(source="../assets/graphics/particles/yellow.png")]
private const YELLOW:Class;
[Embed(source="../assets/graphics/particles/blue.png")]
private const BLUE:Class;
public function Coin_Collect_Trail()
{
graphic = _emitter;
layer = -3;
}
public function particleCreate(_x:Number, _y:Number, explosion:int):void
{
x = _x;
y = _y;
if (explosion == 1)
{
_emitter = new Emitter(YELLOW, 1, 1);
_emitter.newType("1", [0, 1, 2, 3, 4, 5, 6, 7]);
_emitter.setAlpha("1", 1, 0);
_emitter.setMotion("1", 0, 5, 1, 15, 30, 5, Ease.quadOut);
}
else
{
_emitter = new Emitter(RED, 1, 1);
_emitter.newType("2", [0, 1, 2, 3, 4, 5, 6, 7]);
_emitter.setAlpha("2", 1, 0);
_emitter.setMotion("2", 0, 5, 1, 15, 30, .5, Ease.quadOut);
}
if (explosion == 1)
{
for (var amount:int = 4; amount > 0; amount --)
{
_emitter.emit("1", _x, _y) ;
}
}else if (explosion == 2)
{
for (var amount2:int = 4; amount2 > 0; amount2 --)
{
_emitter.emit("2", _x, _y) ;
}
}
}
}
And finally, in the actual box entity class:
GV.BOX_EMITTER .particleCreate(x + 1, y + 248, 1);
the other box has the same code but with a “2” at the end, as I want it to output blue particles
Thank you! This is killing me