Files
MonoGame.Extended/source/MonoGame.Extended/Particles/Modifiers/OpacityFastFadeModifier.cs
T
Christopher Whitley 2ea7e85398 Updates to particle system for ember editor (#1001)
* Add enabled state for modifiers

* Add enabled state for interpolators

* Move AutoTrigger to effect not emitters

* Remove LineUniformProfile

* Set Enabled field true by default

* Don't render invisible emitters

* Remove unused member

* Document update method

* Add documentation

* Remove test now that LineUniformProfile was removed

* Fix unit tests
2025-07-25 00:52:05 -04:00

47 lines
1.5 KiB
C#

// Copyright (c) Craftwork Games. All rights reserved.
// Licensed under the MIT license.
// See LICENSE file in the project root for full license information.
using MonoGame.Extended.Particles.Data;
namespace MonoGame.Extended.Particles.Modifiers;
/// <summary>
/// A modifier that rapidly decreases particle opacity based on their age.
/// </summary>
/// <remarks>
/// The <see cref="OpacityFastFadeModifier"/> creates a linear fade-out effect where particles
/// become more transparent as they age.
///
/// Important notes:
/// <list type="bullet">
/// <item>
/// This modifier assumes particles have a standard lifespan of 1.0 second. For particles
/// with different lifespans, the fade effect may not complete before the particle is removed,
/// or may become fully transparent before the particle's actual end of life.
/// </item>
/// <item>
/// Unlike other modifiers that accumulate changes over time, this modifier directly sets
/// the opacity value each frame based solely on the particle's age.
/// </item>
/// </list>
/// </remarks>
public sealed class OpacityFastFadeModifier : Modifier
{
/// <summary>
/// Updates all particles by setting their opacity based on their age.
/// </summary>
/// <inheritdoc/>
public override unsafe void Update(float elapsedSeconds, ParticleIterator iterator)
{
if (!Enabled) { return; }
while (iterator.HasNext)
{
Particle* particle = iterator.Next();
particle->Opacity = 1.0f - particle->Age;
}
}
}