SpawnComponent.periodRange constructor

SpawnComponent.periodRange({
  1. required double minPeriod,
  2. required double maxPeriod,
  3. PositionComponent factory(
    1. int amount
    )?,
  4. List<PositionComponent> multiFactory(
    1. int amount
    )?,
  5. Shape? area,
  6. bool within = true,
  7. bool selfPositioning = false,
  8. bool autoStart = true,
  9. bool spawnWhenLoaded = false,
  10. Random? random,
  11. ComponentKey? key,
})

Use this constructor if you want your components to spawn within an interval time range. minPeriod will be the minimum amount of time before the next component spawns and maxPeriod will be the maximum amount of time before it spawns.

Implementation

SpawnComponent.periodRange({
  required double this.minPeriod,
  required double this.maxPeriod,
  PositionComponent Function(int amount)? factory,
  List<PositionComponent> Function(int amount)? multiFactory,
  this.area,
  this.within = true,
  this.selfPositioning = false,
  this.autoStart = true,
  this.spawnWhenLoaded = false,
  Random? random,
  super.key,
})  : assert(
        !(selfPositioning && area != null),
        "Don't set an area when you are using selfPositioning=true",
      ),
      _period = minPeriod +
          (random ?? randomFallback).nextDouble() * (maxPeriod - minPeriod),
      multiFactory = multiFactory ?? _wrapFactory(factory!),
      _random = random ?? randomFallback;