Example #1
0
        /// <summary>
        /// Returns a pre-configured emitter with an explosion effect that
        /// can be radial or directional.
        /// </summary>
        /// <param name="particleChain">The particle chain to emit. If it has
        /// more than one frame it will be animated.</param>
        /// <param name="power">How strong the effect will be.</param>
        /// <param name="lifeSeconds">How long particles take to fade out.</param>
        /// <param name="wedgeDegrees">How many degrees the emission wedge is, 360 is radial.</param>
        /// <param name="scalePerSecond">How much particles scale per second.</param>
        /// <param name="area">The area to emit particles, leave at 1 for point emission.</param>
        /// <returns>An EasyEmitter instance</returns>
        public static EasyEmitter BuildExplosion(
            AnimationChain particleChain,
            EmitterPower power   = EmitterPower.Medium,
            float lifeSeconds    = 1f,
            float wedgeDegrees   = 360f,
            float scalePerSecond = 0f,
            float area           = 1f)
        {
            var emitter = new EasyEmitter();

            emitter.emitterPower = power;
            var scale          = GetTextureScale(particleChain);
            var radialVelocity = (float)power * VelocitySizeCoefficient * (1 - VelocityRangePercent);
            var radialRange    = (float)power * VelocitySizeCoefficient * VelocityRangePercent;

            emitter.EmissionSettings = new EmissionSettings
            {
                Alpha                  = 1f,
                AlphaRate              = -1f / lifeSeconds,
                AnimationChain         = particleChain,
                Animate                = true,
                Drag                   = DefaultDrag,
                ScaleX                 = scale.X,
                ScaleY                 = scale.Y,
                ScaleXRange            = scale.X * 0.65f,
                ScaleYRange            = scale.Y * 0.65f,
                ScaleXVelocity         = scalePerSecond,
                ScaleYVelocity         = scalePerSecond,
                RotationZ              = -PiFloat,
                RotationZRange         = PiFloat * 2f,
                RotationZVelocity      = -RotationVelocity,
                RotationZVelocityRange = RotationVelocity * 2f,
                RadialVelocity         = radialVelocity,
                RadialVelocityRange    = radialRange,
                VelocityRangeType      = RangeType.Wedge,
                WedgeAngle             = 0,
                WedgeSpread            = wedgeDegrees * (PiFloat / 180f)
            };

            emitter.TimedEmission     = false;
            emitter.SecondFrequency   = 0.1f;
            emitter.RemovalEvent      = Emitter.RemovalEventType.Alpha0;
            emitter.AreaEmission      = AreaEmissionType.Rectangle;
            emitter.ScaleX            = area / 2f;
            emitter.ScaleY            = area / 2f;
            emitter.NumberPerEmission = ExplosionParticles[power];

            return(emitter);
        }
Example #2
0
        /// <summary>
        /// Returns a pre-configured emitter that can emit distance-based contrail
        /// effects.
        /// </summary>
        /// <param name="particleChain">The particle chain to emit. If it has more
        /// than one frame it will be animated.</param>
        /// <param name="power">How strong the effect will be.</param>
        /// <param name="distance">How long the parent entity travels before triggering
        /// another emission.</param>
        /// <param name="lifeSeconds">How long particles take to fade out.</param>
        /// <param name="scalePerSecond">How much particles scale per second.</param>
        /// <param name="area">The area to emit particles, leave at 1 for point emission.</param>
        /// <returns>An EasyEmitter instance</param>
        /// <returns></returns>
        public static EasyEmitter BuildContrail(
            AnimationChain particleChain,
            EmitterPower power   = EmitterPower.Medium,
            float distance       = 8f,
            float lifeSeconds    = 3f,
            float scalePerSecond = 2f,
            float area           = 1f)
        {
            var emitter = new EasyEmitter();

            emitter.emitterPower     = power;
            emitter.emissionDistance = distance;
            var scale = GetTextureScale(particleChain);

            emitter.EmissionSettings = new EmissionSettings
            {
                Alpha                  = 1f,
                AlphaRate              = -1f / lifeSeconds,
                AnimationChain         = particleChain,
                Animate                = true,
                Drag                   = DefaultDrag,
                ScaleY                 = scale.Y,
                ScaleYRange            = scale.Y * 0.45f,
                ScaleYVelocity         = scalePerSecond,
                MatchScaleXToY         = true,
                RotationZ              = -PiFloat,
                RotationZRange         = PiFloat * 2f,
                RotationZVelocity      = -0.5f,
                RotationZVelocityRange = 1f,
                VelocityRangeType      = RangeType.Radial
            };

            emitter.TimedEmission     = false;
            emitter.RemovalEvent      = Emitter.RemovalEventType.Alpha0;
            emitter.AreaEmission      = AreaEmissionType.Rectangle;
            emitter.ScaleX            = area / 2f;
            emitter.ScaleY            = area / 2f;
            emitter.NumberPerEmission = ContrailParticles[power];

            return(emitter);
        }