public void Update(GameTime gameTime) { if (Paused) { return; } //Update the total time totalTimeAlive += (float)gameTime.ElapsedGameTime.TotalMilliseconds; //Handle being dead if (totalTimeAlive > EmitterLifespanMs || !Alive) { Kill(); return; } //Cache the initial value so we can do computations and get the exact position var currentEmissionArea = EmissionArea; //And move the emitter to its starting position var emitterDelta = EmitterVelocity * (float)gameTime.ElapsedGameTime.TotalSeconds; //Move the emitter based on the velocity EmissionArea = new RectangleF(EmissionArea.X + emitterDelta.X, EmissionArea.Y + emitterDelta.Y, EmissionArea.Width, EmissionArea.Height); //Keep track of how many particles we can create int numberOfParticlesToCreate = GetNumberOfParticlesToCreate(); if (numberOfParticlesToCreate <= 0) { return; //No particles to make, nothing to do } //Spawn the particles for (var i = 0; i < numberOfParticlesToCreate; i++) { //Get one of the allowed assets (randomly) var asset = BasicHelpers.ChooseRandom(Sprites); var fadeOutTime = GetRandomBetween(MinFadeOutMs, MaxFadeOutMs); var fadeInTime = GetRandomBetween(MinFadeInMs, MaxFadeInMs); Vector2 velocity = GetRandomBetween(MinVelocity, MaxVelocity); Vector2 acceleration = GetRandomBetween(MinAcceleration, MaxAcceleration); float rotation = GetRandomBetween(MinRotation, MaxRotation); //Get the size and scale either uniformly or randomly Vector2 size; if (ScaleUniform) { var factor = GetRandomBetween(0, 1); var distX = MaxSize.X - MinSize.X; var distY = MaxSize.Y - MinSize.Y; size = new Vector2(distX * factor + MinSize.X, distY * factor + MinSize.Y); } else { size = GetRandomBetween(MinSize, MaxSize); } //Do you really have to ask with that variable name? if (CalculateVelocityAndAccelerationRelativeToRotation) { var rotationRel = new Vector2( (float)Math.Sin(rotation), (float)-Math.Cos(rotation) ); velocity *= rotationRel; acceleration *= rotationRel; } //And create the actual particle var particle = new Particle() { Acceleration = acceleration, SpriteInfo = asset, ColorMask = GetRandomBetween(MinColorMask, MaxColorMask), FadeInMs = fadeInTime, FadeOutMs = fadeOutTime, LifespanMs = GetRandomBetween(MinLifespanMs, MaxLifespanMs) + fadeInTime + fadeOutTime, Position = GetRandomPosition(currentEmissionArea), Rotation = rotation, RotationVelocity = GetRandomBetween(MinRotationVelocity, MaxRotationVelocity), Size = size, Velocity = velocity, RenderBelowObjects = RenderBelowObjects, GrowInsteadOfFadeIn = ShrinkInsteadOfFadeOut, ShinkInsteadOfFadeOut = ShrinkInsteadOfFadeOut }; //Move the emitter to the exact location it should be for this particle var exactEmitterDelta = EmitterVelocity * (((float)i / numberOfParticlesToCreate) * (float)gameTime.ElapsedGameTime.TotalSeconds); //Move the emitter based on the velocity currentEmissionArea = new RectangleF(EmissionArea.X + exactEmitterDelta.X, EmissionArea.Y + exactEmitterDelta.Y, EmissionArea.Width, EmissionArea.Height); //And add it to the list Container.AddParticle(particle); totalParticlesCreated++; //Note that we created another particle } }