$update method

void $update(
  1. GSimpleParticleSystem emitter,
  2. double delta
)

(Internal usage) Updates the particle's properties based on the elapsed time since creation.

This method is called once per frame by the GSimpleParticleSystem to update the particle's position, rotation, scale, color, and velocity based on the elapsed time since creation.

The emitter parameter is the emitter that the particle belongs to.

The delta parameter is the delta time elapsed since the last tick.

Implementation

void $update(GSimpleParticleSystem emitter, double delta) {
  accumulatedEnergy += delta;
  // If the accumulated energy exceeds the particle's total energy, it has
  // run out of energy and should be deactivated.
  if (accumulatedEnergy >= energy) {
    emitter.$deactivateParticle(this);
    return;
  }

  // Update the particle's velocity based on its acceleration.
  velocityX += accelerationX * delta;
  velocityY += accelerationY * delta;

  // Calculate the progress of the particle's life cycle as a value between
  // 0.0 and 1.0, based on the accumulated energy.
  final percent = accumulatedEnergy / energy;

  // Calculate the particle's color as an interpolated value between its
  // initial and end color, based on the progress of its life cycle.
  red = _redDif * percent + initialRed;
  green = _greenDif * percent + initialGreen;
  blue = _blueDif * percent + initialBlue;
  alpha = _alphaDif * percent + initialAlpha;

  // Update the particle's position, rotation, and scale based on its
  // velocity and scale difference.
  x += velocityX * delta;
  y += velocityY * delta;
  rotation += initialVelocityAngular * delta;
  scaleX = scaleY = _scaleDif * percent + initialScale;
}