First you need ParticleManager instance in your class (smoke for example)
smoke = new ParticlesManager(1000, ParticleState.Update_particle, true); emitterPosition = new Point(stageWidth + 40, stageHeight / 3); addChild(smoke);
Then in some loop of your game (EnterFrame?) you have to emit particles
var speed_x:Float = -20 * (Math.random()) - 20; var speed_y:Float = 14 * (Math.random()) - 7; var state:ParticleState = new ParticleState(new Point(speed_x, speed_y), 1); smoke.Create_particle(Assets.getBitmapData("assets/round_20.png"), new Point(emitterPosition.x, emitterPosition.y), 0xff0000ff, 30, new Point(0.1, 0.1), state, 0, 0.2, 0.04); // look at ParticleManager code for params description
As you can see, you need ParticleState class for particles
package; import flash.geom.Point; import particles.Particle; class ParticleState { public var velocity:Point; public var lengthMultiplier:Float = 0.0; public function new(velocity:Point, lengthMultiplier:Float) { this.velocity = velocity; this.lengthMultiplier = lengthMultiplier; } public static function Update_particle(particle:Particle):Void //here you have to define how particles move { var vel:Point = particle.state.velocity; particle.position.x += vel.x; particle.position.y += vel.y; particle.bitmap.scaleX += (1 - particle.bitmap.scaleX) * particle.sizeReduction; particle.bitmap.scaleY += (1 - particle.bitmap.scaleX) * particle.sizeReduction; particle.bitmap.alpha -= particle.fading; } }
No comments:
Post a Comment