Exemple #1
0
        protected virtual ParticleT createParticle(float elepsedS)
        {
            float percentage = this.calculateEmitterPercentage();

            // Calculate the lifetime
            float lifetime = 1f;

            if (this.AverageLifetimes.Length == 1)
            {
                lifetime = this.AverageLifetimes[0].Value;
            }
            else
            {
                int i = this.AverageLifetimes.GetToIndex(percentage);
                lifetime = GameMath.Lerp(this.AverageLifetimes[i - 1].Value, this.AverageLifetimes[i].Value, AverageLifetimes.GetLerpFactor(i, percentage));
            }
            lifetime = (float)GlobalRandom.Rand(this.Distribution, lifetime, this.LifeTimeDeviation);

            // Adjust the scales
            PercentageArray <float> scales = this.ScalePercentages.Clone();

            if (ScaleDiesToo)
            {
                float factor = lifetime / this.AverageLifetimes[0].Value;
                for (int i = 0; i < scales.Length; i++)
                {
                    scales[i].Value = scales[i].Value * factor;
                }
            }

            // Adjust the alphas
            PercentageArray <float> alphas = this.AlphaPercentages.Clone();

            if (AlphaDiesToo)
            {
                float factor = lifetime / this.AverageLifetimes[0].Value;
                for (int i = 0; i < alphas.Length; i++)
                {
                    alphas[i].Value = alphas[i].Value * factor;
                }
            }

            // Create the particle
            ParticleT particle = this.createParticle(elepsedS, lifetime, scales, alphas);

            return(particle);
        }
Exemple #2
0
        public virtual void Draw(UpdateEventArgs e)
        {
            // Don't draw dead particles
            if (timeLeft <= 0)
            {
                return;
            }

            // Calculate the colour
            Color color = Color.White;
            float pct   = 100f * (1f - this.timeLeft / this.lifeTime);

            if (this.colorPercentages.Length == 1)
            {
                color = this.colorPercentages[0].Value;
            }
            else
            {
                int i = this.colorPercentages.GetToIndex(pct);
                color = GameMath.Lerp(this.colorPercentages[i - 1].Value, this.colorPercentages[i].Value, colorPercentages.GetLerpFactor(i, pct));
            }

            // Calculate the scale
            float scale = 1f;

            if (this.scalePercentages.Length == 1)
            {
                scale = this.scalePercentages[0].Value;
            }
            else
            {
                int i = this.scalePercentages.GetToIndex(pct);
                scale = GameMath.Lerp(this.scalePercentages[i - 1].Value, this.scalePercentages[i].Value, scalePercentages.GetLerpFactor(i, pct));
            }

            // Calculate the alpha
            float alpha = 1f;

            if (this.alphaPercentages.Length == 1)
            {
                alpha = this.alphaPercentages[0].Value;
            }
            else
            {
                int i = this.alphaPercentages.GetToIndex(pct);
                alpha = GameMath.Lerp(this.alphaPercentages[i - 1].Value, this.alphaPercentages[i].Value, alphaPercentages.GetLerpFactor(i, pct));
            }

            // Draw the sprite
            color.A = (byte)(255 * alpha);
            this.draw(this.position, scale, color);
        }