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