update method

void update({
  1. double? x,
  2. double? y,
  3. double? scale,
  4. double? rotation,
  5. int? frame,
  6. Color? color,
  7. double? vx,
  8. double? vy,
  9. double? lifespan,
  10. double? age,
})

Sets any values passed, and runs basic logic:

  • if neither x or y are specified, adds vx / vy to them
  • if age is not specified, increments it by one

This is provided for convenience, and does not need to be used.

Implementation

void update({
  double? x,
  double? y,
  double? scale,
  double? rotation,
  int? frame,
  Color? color,
  double? vx,
  double? vy,
  double? lifespan,
  double? age,
}) {
  if (x != null) this.x = x;
  if (y != null) this.y = y;
  if (scale != null) this.scale = scale;
  if (rotation != null) this.rotation = rotation;
  if (frame != null) this.frame = frame;
  if (color != null) this.color = color;

  if (vx != null) this.vx = vx;
  if (vy != null) this.vy = vy;
  if (lifespan != null) this.lifespan = lifespan;
  this.age = age ?? this.age + 1;

  if (x == null && y == null) {
    this.x += this.vx;
    this.y += this.vy;
  }
}