SpawnComponent constructor

SpawnComponent({
  1. required PositionComponent factory(
    1. int amount
    ),
  2. required double period,
  3. Shape? area,
  4. bool within = true,
  5. bool selfPositioning = false,
  6. bool autoStart = true,
  7. bool spawnWhenLoaded = false,
  8. Random? random,
  9. ComponentKey? key,
})

The SpawnComponent is a non-visual component which can spawn PositionComponents randomly within a set area. If area is not set it will use the size of the nearest ancestor that provides a size. period will set the static time interval for when it will spawn new components. If you want to use a non static time interval, use the SpawnComponent.periodRange constructor. If you want to set the position of the spawned components yourself inside of the factory, set selfPositioning to true.

Implementation

SpawnComponent({
  required this.factory,
  required double period,
  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 = period,
      _random = random ?? randomFallback;