示例#1
0
        /// <summary>
        /// This method will generate particles for a Default Particle Effect.
        /// </summary>
        /// <param name="particleEngine">The Particle Engine that will use this effect.</param>
        public override Particle GenerateParticle(ParticleEngine particleEngine)
        {
            // Pick a random texture from the texture list available
            Texture2D texture = particleEngine.Textures[random.Next(particleEngine.Textures.Count)];

            // Set the location of the new particle based upon the emitter location
            Vector2 position = particleEngine.EmitterLocation;

            // Set the velocity for the new particle using random generated values
            Vector2 velocity = new Vector2(
                1f * (float)(random.NextDouble() * 2 - 1),
                1f * (float)(random.NextDouble() * 2 - 1));

            float angle = 0;

            // Set a random angularvelocity (spinning)
            float angularVelocity = 0.1f * (float)(random.NextDouble() * 2 - 1);

            // Set a random color for this particle
            Color color = new Color(
                (float)random.NextDouble(),
                (float)random.NextDouble(),
                (float)random.NextDouble());

            // Set a random size for this particle
            float size = (float)random.NextDouble() * startingScale;

            // Set a random ttl for this particle (minimum 5)
            int ttl = 20 + random.Next(40);

            // Set the total number of particles for this effect
            particleEngine.TotalParticles = numberOfParticles;

            // Return a new particle generated according to the above
            return(new Particle(texture, position, velocity, angle, angularVelocity, color, size, ttl));
        }
示例#2
0
 /// <summary>
 /// A Particle Effect needs to implement a GenerateParticle() method.
 /// </summary>
 /// <param name="particleEngine">The Particle Engine that will use this. Needed for EmitterLocation and access to totalParticles field.</param>
 public abstract Particle GenerateParticle(ParticleEngine particleEngine);