ScaleInterpolator.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132
  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 Microsoft.Xna.Framework;
  5. using MonoGame.Extended.Particles.Data;
  6. namespace MonoGame.Extended.Particles.Modifiers.Interpolators;
  7. /// <summary>
  8. /// An interpolator that gradually changes the size of particles over their lifetime.
  9. /// </summary>
  10. /// <remarks>
  11. /// The <see cref="ScaleInterpolator"/> transitions a particle's scale factor from the inherited
  12. /// <see cref="Interpolator{T}.StartValue"/> to <see cref="Interpolator{T}.EndValue"/> based on the
  13. /// provided interpolation amount (typically representing the particle's normalized age).
  14. /// </remarks>
  15. public class ScaleInterpolator : Interpolator<Vector2>
  16. {
  17. /// <summary>
  18. /// Updates a particle's scale by interpolating between the start and end values.
  19. /// </summary>
  20. /// <param name="amount">The normalized interpolation amount (from 0.0 to 1.0).</param>
  21. /// <param name="particle">A pointer to the particle to update.</param>
  22. public override unsafe void Update(float amount, Particle* particle)
  23. {
  24. if (!Enabled) { return; }
  25. particle->Scale[0] = StartValue.X + (EndValue.X - StartValue.X) * amount;
  26. particle->Scale[1] = StartValue.Y + (EndValue.Y - StartValue.Y) * amount;
  27. }
  28. }