OpacityInterpolator.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright (c) Craftwork Games. All rights reserved.
  2. // Licensed under the MIT license.
  3. // See LICENSE file in the project root for full license information.
  4. using MonoGame.Extended.Particles.Data;
  5. namespace MonoGame.Extended.Particles.Modifiers.Interpolators;
  6. /// <summary>
  7. /// An interpolator that gradually changes the opacity of particles over their lifetime.
  8. /// </summary>
  9. /// <remarks>
  10. /// <para>
  11. /// The <see cref="OpacityInterpolator"/> transitions a particle's opacity (alpha) value from the inherited
  12. /// <see cref="Interpolator{T}.StartValue"/> to <see cref="Interpolator{T}.EndValue"/> based on the
  13. /// provided interpolation amount.
  14. /// </para>
  15. /// <para>
  16. /// Valid opacity values range from 0.0 (completely transparent) to 1.0 (completely opaque).
  17. /// </para>
  18. /// </remarks>
  19. public class OpacityInterpolator : Interpolator<float>
  20. {
  21. /// <summary>
  22. /// Updates a particle's opacity by interpolating between the start and end values.
  23. /// </summary>
  24. /// <param name="amount">The normalized interpolation amount (from 0.0 to 1.0).</param>
  25. /// <param name="particle">A pointer to the particle to update.</param>
  26. public override unsafe void Update(float amount, Particle* particle)
  27. {
  28. if (!Enabled) { return; }
  29. particle->Opacity = StartValue + (EndValue - StartValue) * amount;
  30. }
  31. }