SpawnComponent.periodRange constructor
SpawnComponent.periodRange({
- required PositionComponent factory(
- int amount
- required double minPeriod,
- required double maxPeriod,
- Shape? area,
- bool within = true,
- bool selfPositioning = false,
- bool autoStart = true,
- Random? random,
- 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,
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;