Engines/FlatRedBallXNA/FlatRedBall/Graphics/Particle/Emitter.cs
/// <summary>
/// Emits particles as specified by the Emitter class
/// </summary>
/// <remarks>
/// This method initiates one emission of particles.  The number of particles emitted
/// depends on the numberPerEmission variable.  This method does not consider emission timing, and the time
/// is not recorded for emission timing.  
/// 
/// The argument SpriteList stores all Sprites which were emitted
/// during the call.  The Sprites are added regularly, rather than in a one way relationship.  This enables
/// modification of emitted particles after the method ends.  null can be passed as an argument
/// if specific action is not needed for emitted particles.  Particles are automatically created
/// through the SpriteManager as Particle Sprites.
/// <seealso cref="FlatRedBall.Graphics.Particle.Emitter.TimedEmit()"/>
/// <seealso cref="FlatRedBall.SpriteManager.AddParticleSprite"/>
/// 
/// </remarks>
/// <param name="spriteList">The list of Sprites (which can be null) to add all Sprites created
/// by this call.</param>
Emits particles as specified by the Emitter class
Emits particles as specified by the Emitter class
public void Emit(SpriteList spriteList)
        {
            UpdateDependencies(TimeManager.CurrentTime);
            if (mBoundedEmission && mEmissionBoundary != null)
            {
                float cameraDistance;
#if FRB_MDX
                cameraDistance = -SpriteManager.Camera.Z;
#else
                cameraDistance = SpriteManager.Camera.Z;
#endif
                if (cameraDistance < 0) return; 
                cameraRectangle.Position = new Vector3(SpriteManager.Camera.X, SpriteManager.Camera.Y, 0);
                cameraRectangle.ScaleY = SpriteManager.Camera.YEdge * cameraDistance / 100;
                cameraRectangle.ScaleX = cameraRectangle.ScaleY * SpriteManager.Camera.AspectRatio;
                if (!mEmissionBoundary.CollideAgainst(cameraRectangle))
                {
                    return;
                }
            }
            #region loop through creating NumberPerEmission particles
            for (int i = 0; i < NumberPerEmission; i++)
            {
                #region Create the tempParticle (the Sprite instance)
                Sprite tempParticle = null;
                if (mEmitsAutomaticallyUpdatedSprites)
                {
                    tempParticle = SpriteManager.AddParticleSprite(EmissionSettings.Texture);
                }
                else
                {
                    tempParticle = SpriteManager.AddManualParticleSprite(EmissionSettings.Texture);
                }
                #endregion
                #region Removal events
                switch ((int)this.RemovalEvent)
                {
                    case (int)RemovalEventType.Alpha0:
                        SpriteManager.mRemoveWhenAlphaIs0.Add(tempParticle);
                        break;
                    case (int)RemovalEventType.OutOfScreen:
                        tempParticle.CustomBehavior += FlatRedBall.Utilities.CustomBehaviorFunctions.RemoveWhenOutsideOfScreen;
                        break;
                    case (int)RemovalEventType.Timed:
#if FRB_MDX
                        tempParticle.Instructions.Add(
                            new FlatRedBall.Instructions.StaticMethodInstruction(
                                sSpriteManagerRemoveSprite,
                                new object[] { tempParticle },
                                TimeManager.CurrentTime + (mSecondsLasting * mSecondsModifier)));
#else                
                        SpriteManager.mTimedRemovalList.InsertSorted(tempParticle,
                            TimeManager.CurrentTime + (mSecondsLasting * mSecondsModifier));
#endif
                        break;
                }
                #endregion
                if (tempParticle == null)
                {
                }
                #region Sprite-specific stuff (not stuff that other types can do, which are handled below)
                tempParticle.mVertices[0].TextureCoordinate.X = 0;
                tempParticle.mVertices[3].TextureCoordinate.X = 0;
                tempParticle.mVertices[1].TextureCoordinate.X = 1;
                tempParticle.mVertices[2].TextureCoordinate.X = 1;
                tempParticle.mVertices[0].TextureCoordinate.Y = 0;
                tempParticle.mVertices[1].TextureCoordinate.Y = 0;
                tempParticle.BottomTextureCoordinate = 1;
                if (EmissionSettings.AnimationChains != null)
                {
                    tempParticle.AnimationChains = EmissionSettings.AnimationChains;
                }
                tempParticle.SetAnimationChain(EmissionSettings.AnimationChain);
                tempParticle.CurrentFrameIndex = 0;
                tempParticle.Animate = EmissionSettings.Animate;
                if (EmissionSettings.Billboarded)
                {
                    SpriteManager.Camera.AddSpriteToBillboard(tempParticle);
                }
                if (spriteList != null) spriteList.Add(tempParticle);
                if (mLayerToEmitOn != null)
                {
                    SpriteManager.AddToLayer(tempParticle, mLayerToEmitOn);
                }
                #endregion
                SetPositionedObjectProperties(tempParticle);
                SetSpriteScaleProperties(tempParticle);
                SetColorableProperties(tempParticle);
            }
            #endregion
        }
public void Emit ( SpriteList spriteList ) { UpdateDependencies ( TimeManager . CurrentTime ) ; if ( mBoundedEmission && mEmissionBoundary != null ) { float cameraDistance ; if FRB_MDX cameraDistance = - SpriteManager . Camera . Z ; else cameraDistance = SpriteManager . Camera . Z ; endif if ( cameraDistance < 0 ) return ; cameraRectangle . Position = new Vector3 ( SpriteManager . Camera . X , SpriteManager . Camera . Y , 0 ) ; cameraRectangle . ScaleY = SpriteManager . Camera . YEdge * cameraDistance / 100 ; cameraRectangle . ScaleX = cameraRectangle . ScaleY * SpriteManager . Camera . AspectRatio ; if ( ! mEmissionBoundary . CollideAgainst ( cameraRectangle ) ) { return ; } } region  loop through creating NumberPerEmission particles for ( int i = 0 ; i < NumberPerEmission ; i ++ ) { region  Create the tempParticle (the Sprite instance) Sprite tempParticle = null ; if ( mEmitsAutomaticallyUpdatedSprites ) { tempParticle = SpriteManager . AddParticleSprite ( EmissionSettings . Texture ) ; } else { tempParticle = SpriteManager . AddManualParticleSprite ( EmissionSettings . Texture ) ; } endregion region  Removal events switch ( ( int ) this . RemovalEvent ) { case ( int ) RemovalEventType . Alpha0 : SpriteManager . mRemoveWhenAlphaIs0 . Add ( tempParticle ) ; break ; case ( int ) RemovalEventType . OutOfScreen : tempParticle . CustomBehavior += FlatRedBall . Utilities . CustomBehaviorFunctions . RemoveWhenOutsideOfScreen ; break ; case ( int ) RemovalEventType . Timed : if FRB_MDX tempParticle . Instructions . Add ( new FlatRedBall . Instructions . StaticMethodInstruction ( sSpriteManagerRemoveSprite , new object [ ] { tempParticle } , TimeManager . CurrentTime + ( mSecondsLasting * mSecondsModifier ) ) ) ; else SpriteManager . mTimedRemovalList . InsertSorted ( tempParticle , TimeManager . CurrentTime + ( mSecondsLasting * mSecondsModifier ) ) ; endif break ; } endregion if ( tempParticle == null ) { } region  Sprite-specific stuff (not stuff that other types can do, which are handled below) tempParticle . mVertices [ 0 ] . TextureCoordinate . X = 0 ; tempParticle . mVertices [ 3 ] . TextureCoordinate . X = 0 ; tempParticle . mVertices [ 1 ] . TextureCoordinate . X = 1 ; tempParticle . mVertices [ 2 ] . TextureCoordinate . X = 1 ; tempParticle . mVertices [ 0 ] . TextureCoordinate . Y = 0 ; tempParticle . mVertices [ 1 ] . TextureCoordinate . Y = 0 ; tempParticle . BottomTextureCoordinate = 1 ; if ( EmissionSettings . AnimationChains != null ) { tempParticle . AnimationChains = EmissionSettings . AnimationChains ; } tempParticle . SetAnimationChain ( EmissionSettings . AnimationChain ) ; tempParticle . CurrentFrameIndex = 0 ; tempParticle . Animate = EmissionSettings . Animate ; if ( EmissionSettings . Billboarded ) { SpriteManager . Camera . AddSpriteToBillboard ( tempParticle ) ; } if ( spriteList != null ) spriteList . Add ( tempParticle ) ; if ( mLayerToEmitOn != null ) { SpriteManager . AddToLayer ( tempParticle , mLayerToEmitOn ) ; } endregion SetPositionedObjectProperties ( tempParticle ) ; SetSpriteScaleProperties ( tempParticle ) ; SetColorableProperties ( tempParticle ) ; } endregion }
Emits particles as specified by the Emitter class
Emits particles as specified by the Emitter class
// skip check bounding if camera is behind z = 0 plain // August 28, 2012 // The following code // was added during Sentient // to fix some issue with particles // not being removed when paused.  Not // sure what the problem was, but this bug // causes particles to be immediately removed // if they are spawned when the game is paused - // at least most of the time.  The reason is because // when the game is paused, then the CurrentTime is 0 // which means the particle is told to be removed at a  // time very close to 0.  Usually this is in the past so // any particles spawned when the game is paused will immediately // be removed.  Not sure what the intent was here... //double isEnginePaused = 1.0; //if( InstructionManager.IsEnginePaused ) //{ //    isEnginePaused = 0.0; //}                        //                        SpriteManager.RemoveSpriteInstruction(tempParticle, TimeManager.CurrentTimeAfterXSeconds(SecondsLasting)); // do something here with the SpriteManager.  Probably call some event // manually inlined for speed: //tempParticle.LeftTextureCoordinate = 0; //tempParticle.RightTextureCoordinate = 1; //tempParticle.TopTextureCoordinate = 0; // Use the setter here to call UpdateScale // Justin Johnson, 04/2015 - retiring particle blueprints // Use the animation chain from the  // emission settings instead of setting // the animation based on chains and chain name //tempParticle.AnimationChains = mParticleBlueprint.AnimationChains; //if (!string.IsNullOrEmpty(mParticleBlueprint.CurrentChainName )) //{ //    tempParticle.CurrentChainName = mParticleBlueprint.CurrentChainName; //    tempParticle.Animate = mParticleBlueprint.Animate; //    tempParticle.CurrentFrameIndex = 0; //    //                return; //} //SetScalableProperties(tempParticle); // this sets the CustomBehavior to null so be sure not to call this after // setting any CustomBehavior. // Update on March 7, 2011:  CustomBehaviors are falling // out of style.  Particles no longer support them. // tempParticle.CopyCustomBehaviorFrom(mParticleBlueprint);
spriteList
SpriteList
The list of Sprites (which can be null) to add all Sprites created
by this call.
The list of Sprites ( which can be null ) to add all Sprites created by this call .
remarks
This method initiates one emission of particles.  The number of particles emitted
depends on the numberPerEmission variable.  This method does not consider emission timing, and the time
is not recorded for emission timing.

The argument SpriteList stores all Sprites which were emitted
during the call.  The Sprites are added regularly, rather than in a one way relationship.  This enables
modification of emitted particles after the method ends.  null can be passed as an argument
if specific action is not needed for emitted particles.  Particles are automatically created
through the SpriteManager as Particle Sprites.
This method initiates one emission of particles . The number of particles emitted depends on the numberPerEmission variable . This method does not consider emission timing and the time is not recorded for emission timing . The argument SpriteList stores all Sprites which were emitted during the call . The Sprites are added regularly rather than in a one way relationship . This enables modification of emitted particles after the method ends . null can be passed as an argument if specific action is not needed for emitted particles . Particles are automatically created through the SpriteManager as Particle Sprites .