SpawnComponent.periodRange constructor

SpawnComponent.periodRange({
  1. required PositionComponent factory(
    1. int amount
    ),
  2. required double minPeriod,
  3. required double maxPeriod,
  4. Shape? area,
  5. bool within = true,
  6. bool selfPositioning = false,
  7. bool autoStart = true,
  8. bool spawnWhenLoaded = false,
  9. Random? random,
  10. 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 this.factory,
  required double minPeriod,
  required double maxPeriod,
  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),
      _random = random ?? randomFallback;