-
Notifications
You must be signed in to change notification settings - Fork 2
ParticleEmitter
This is a basic Particle Emitter class. It emits a Particle that is an extension of an Entity (so feel free to use Components when composing your particles!).
The first step in using this class is to create your own particle:
import zero.flixel.ec.ParticleEmitter;
import zero.flixel.ec.components.KillAfterAnimation;
using zero.flixel.extensions.FlxSpriteExt;
class Spark extends Particle
{
public function new()
{
super();
loadGraphic(AssetPaths.spark__png, true, 9, 9);
this.make_and_center_hitbox(1, 1);
animation.add('play', [0, 1, 2, 3, 4, 5], 30, false);
add_component(new KillAfterAnimation());
}
}
This particle is a spark - it loads a graphic, creates an animation, and adds the KillAfterAnimation component.
warning kill()
gets called on your particle somehow so it can be recycled later!
Since we created our own unique Particle, we need to tell our ParticleEmitter how to create it so it can be used, we do that when we initialize our emitter (don't forget to add the emitter to the state!):
var emitter = new ParticleEmitter(() -> new Spark());
add(emitter);
Now your emitter is ready to use! at any point, call fire()
to emit a particle!
emitter.fire({
position: FlxPoint.get(64, 64),
animation: 'play'
});
When you fire a particle you can pass through an object with the following information:
- position (FlxPoint) (required) where to fire the particle from
- velocity (FlxPoint) what direction to fire the particle toward
-
acceleration (FlxPoint) how to accelerate the particle (
FlxPoint.get(0, 25)
would add some gravity!) -
animation (String) what animation to play (notice above we pass the animation
'play'
, otherwise the Spark particle we created would never die and be recycled! - util_amount (Float) a utility option, it could be used however you'd like!
For more info, please check out the API: http://01010111.com/zerolib-flixel/