FlatRedBall.Graphics.Particle.Emitter

Introduction

Emitters are PositionedObjects which are used to create Sprites. The behavior of the created Sprites (such as Velocity and Rotation) depends on the Emitter’s properties.

All Sprites created by Emitters are regular Sprites. This means that they can be modified just like other Sprites after they are emitted.

How to Create an Emitter in Glue

See this page for information on how to add Emitters in Glue.

How to Create an Emitter in Code

Add the following using statement:

using FlatRedBall.Graphics.Particle;

Declare the Emitter at class scope:

Emitter emitter;

Create the Emitter in Initialize after initializing FlatRedBall:

emitter = new Emitter();
SpriteManager.AddEmitter(emitter);
emitter.Texture = FlatRedBallServices.Load<Texture2D>("redball.bmp");

Add the following code in Update:

if (InputManager.Keyboard.KeyDown(Keys.Space))
{
    emitter.Emit();
}

Loading Emitters From File

The following code loads an emitter from an .emix file.

Add the following using statement:

using FlatRedBall.Content.Particle;
using FlatRedBall.Graphics.Particle;

Create the Emitter in Initialize after initializing FlatRedBall:

// Assuming myEmitter.emix is a valid file.
EmitterList emitterList = FlatRedBallServices.Load<EmitterList>(
    "myEmitter.emix", "ContentManagerName");

Alternatively you can use the EmitterSaveList class. This code is functionally identical to the code above:

// Assuming myEmitter.emix is a valid file.
EmitterSaveList emitterSaveList = EmitterSaveList.FromFile(
    "myEmitter.emix");

EmitterList emitterList = emitterSaveList.ToEmitterList("ContentManagerName");

Loading Emitters through Content Pipeline

Emitters are loaded through the Content Pipeline just like any other content type. The FlatRedBallService.Load method can load from content pipeline:

// Assuming myEmitter.emix is a valid file and part of the content pipeline:
EmitterList emitterList = FlatRedBallServices.Load<EmitterList>(
    @"Content\myEmitter", "ContentManagerName");

For more information about loading through the Content Pipeline, see the FlatRedBall XNA Content Pipeline wiki entry.

Timed Emitters

See the TimedEmit entry.

Storing Particle References and Customizing Particle Behavior

See the Emit page.

Particle Blueprint

The ParticleBlueprint property provides control over emitted particles. The following properties are considered when emitting Sprites:

  • Texture
  • CustomBehavior

Velocity Range Type

The VelocityRangeType property in the Emitter’s EmissionSettings gives control over the velocity of the particles that are emitted. The following code creates an emitter that emits in a wedge:

Add the following using statement:

using FlatRedBall.Graphics.Particle;

Add the following at class scope:

Emitter emitter;

Add the following in Initialize after initializing FlatRedBall:

emitter = SpriteManager.AddEmitter("redball.bmp", "ContentManagerName");

emitter.EmissionSettings.RadialVelocity = 3;

emitter.EmissionSettings.WedgeAngle = 0; // straight to the right

emitter.EmissionSettings.WedgeSpread = 
    Microsoft.Xna.Framework.MathHelper.PiOver4;

emitter.EmissionSettings.VelocityRangeType = RangeType.Wedge;

emitter.TimedEmission = true;
emitter.SecondFrequency = .05f;
emitter.RemovalEvent = Emitter.RemovalEventType.OutOfScreen;

Add the following in Update:

emitter.TimedEmit();

WedgeEmission.png

Velocity Range Type and Velocity Properties

The velocity properties that are used in the EmissionSettings depends on the current VelocityRangeType. The following table shows which velocity values are used depending on the VelocityRangeType:

VelocityRangeType Values Considered
RangeType.Component XVelocityXVelocityRangeYVelocityYVelocityRangeZVelocityZVelocityRange
RangeType.Cone WedgeAngleWedgeSpreadRadialVelocityRadialVelocityRange
RangeType.Radial RadialVelocityRadialVelocityRange
RangeType.Spherical RadialVelocityRadialVelocityRange
RangeType.Wedge WedgeAngleWedgeSpreadRadialVelocityRadialVelocityRange

Emission Area

Emitters can have areas defined for emission. This can simplifying the creation of “area” emitters like rain or explosions. The following code creates an emitter that emits in a rectangular area as defined by the Emitter’s scale values.

Add the following using statement:

using FlatRedBall.Graphics.Particle;

Add the following at class scope:

Emitter emitter;

Add the following in Initialize after initializing FlatRedBall:

emitter = SpriteManager.AddEmitter("redball.bmp", "ContentManagerName");

emitter.EmissionSettings.AlphaRate = -.15f;

emitter.EmissionSettings.RadialVelocity = .1f;
emitter.TimedEmission = true;
emitter.SecondFrequency = .02f; 
emitter.RemovalEvent = Emitter.RemovalEventType.Alpha0;

emitter.AreaEmission = Emitter.AreaEmissionType.Rectangle;
emitter.ScaleX = 10;
emitter.ScaleY = 2;

Add the following in Update:

emitter.TimedEmit();

RectangleEmissionArea.png

Emitter Members

Additional Information

Did this article leave any questions unanswered? Post any question in our forums for a rapid response.