ig.

Spawner

new Spawner()

Entity that spawns other entities on activation.
- this entity uses pooling to try to improve performance at the cost of memory
- spawners hook the ig.EntityExtended#onRemoved signal of the entities they spawn to ensure they return to the pool automatically IMPORTANT: this is an abstract entity that should be extended.

Author:
  • Collin Hover - collinhover.com
  • Jesse Freeman
Source:

autoComplete

Default Value:
  • false
Source:

duration :Number

Duration in seconds over which to spawn.

Default Value:
  • 0
Source:
Example
// spawner that spawns all entities instantly
spawner.duration = 0;
// spawner that spawns all entities endlessly
// with an optional 1 second delay between respawning
spawner.duration = -1;
spawner.respawnDelay = 1;
// spawner that spawns all entities over 10 seconds
spawner.duration = 10;

durationTimer :ig.Timer

Timer for duration of spawning.
- created on init

Source:

<readonly> entities :Array

List of entities that have been spawned and are still in game world.

Source:

onSpawned :ig.Signal

Signal dispatched when spawner spawns an entity.
- created on init.

Source:

onSpawnedAll :ig.Signal

Signal dispatched when spawner has finished spawning all entities.
- created on init.

Source:

onUnspawned :ig.Signal

Signal dispatched when spawner unspawns an entity.
- created on init.

Source:

onUnspawnedAll :ig.Signal

Signal dispatched when spawner has unspawned all entities.
- created on init.

Source:

<readonly> pool :Array

List of entities that have been spawned and returned to spawning pool.

Source:

respawnDelay :Number

Respawn delay in seconds when duration of spawn is endless, i.e. -1.

Default Value:
  • 0
Source:

respawnTimer :ig.Timer

Timer for respawn delay.
- created on init

Source:

spawnAndMoveTo :Boolean

Whether to spawn and move to ig.Spawner#spawnAt.
- if there are multiple targets in ig.EntityTrigger#target, spawned will move to each in sequence IMPORTANT: this doesn't do anything unless spawner has multiple targets in ig.EntityTrigger#target.

Default Value:
  • false
Source:

spawnAndMoveToSettings :Object

Settings for moving to ig.Spawner#spawnAt, based directly on settings for ig.EntityExtended#moveTo IMPORTANT: this doesn't do anything unless ig.Spawner#spawnAndMoveTo is true.

Default Value:
  • null
Source:

spawnAt :Boolean|ig.EntityExtended

Entity to spawn entities at.

Default Value:
  • self
Source:

spawnAtFirstTarget :Boolean

Whether to always set ig.Spawner#spawnAt to first target from ig.EntityTrigger#target.

Default Value:
  • false
Source:

spawnAtRandomPosition :Boolean

Whether to spawn at a random position within the bounds of ig.Spawner#spawnAt.

Default Value:
  • true
Source:

spawnAtRandomTarget :Boolean

Whether to find ig.Spawner#spawnAt based on a random target from ig.EntityTrigger#target.

Default Value:
  • false
Source:

spawnAtSide :Vector2|Object

Which side of ig.Spawner#spawnAt to snap spawned entity position to.

Default Value:
  • null
Source:
Example
// this snaps spawned entities to the bottom of a spawner
// which is very useful for creature spawners, which need to spawn on the ground
spawner.spawnAtSide = { x: 0, y: 1 };

<readonly> spawnCount :Number

Number of currently spawned entities.

Source:

spawnCountMax :Number

Total number of entities to spawn over duration.

Default Value:
  • 1
Source:

spawnDelay :Number

Delay between individual spawns.

Source:
Example
// spawner that finds delay automatically based on duration
spawner.spawnDelay = -1;
// spawner that has a 1 second delay between each spawn
spawner.spawnDelay = 1;

<readonly> spawnedCount :Number

Number of spawned entities since first activated.

Source:

spawnedDieWith :Boolean

Whether to kill all spawned entities when spawner dies.

Default Value:
  • false
Source:

<readonly> spawning :Boolean

Whether spawner is currently spawning entities.

Source:

spawningEntity :String|ig.EntityExtended

Entity to spawn. IMPORTANT: spawner does nothing if this is empty!.

Source:

spawnSettings :Object

Settings object applied to each spawned entity, that directly corresponds to properties of spawned entity. Tip: this object is merged into the spawned entity through its init method.

Default Value:
  • null
Source:

spawnTarget :Object

Map of name of entities to spawn entities at.

Source:
Example
// spawner will spawn entities within its own bounds
spawner.spawnTarget = {};
// spawner will spawn entities within the bounds of a void entity
var spawnLocation = ig.game.spawnEntity( ig.EntityVoid, 0, 0 );
spawner.spawnTarget.1 = spawnLocation;

spawnTargetSequence :Array

List of entities to spawn entities at, populated on activate.

Source:

spawnTimer :ig.Timer

Timer for delay between each spawn.
- created on init

Source:

triggerable

Spawners should usually not trigger on collision.

Default Value:
  • false
Source:

triggerAfterDelay

Spawners should always trigger after delay.

Default Value:
  • true
Source:

unspawnSilently :Boolean

Whether to force spawned entities to unspawn silently.

Default Value:
  • true
Source:

activate()

Begins spawning entities if not already spawning or not spawned up to max.

Source:

cleanup()

Cleans up spawner and, if ig.Spawner#spawnedDieWith, also kills all spawned entities.

Source:

complete()

Source:

deactivate(entity, silent)

Stops spawning and unspawns all spawned entities. IMPORTANT: this kills all spawned and return them to spawning pool!

Parameters:
Name Type Argument Default Description
entity ig.EntityExtended entity triggering deactivate.
silent Boolean <optional>
ig.Spawner.unspawnSilently whether to despawn all spawned silently (i.e. no death animations).
Source:

initProperties()

Initializes properties of spawner.
- checks and sets default ig.Spawner#spawnAt
- creates timers for spawning

Source:

linkSpawned()

Adds attachments between spawner and spawned.
- spawners hook the ig.EntityExtended#onRemoved signal of the entities they spawn to ensure they return to the pool automatically
- adds a 'spawner' property to entity with a reference to this spawner

Source:

pause()

Source:

resetExtras()

Resets spawner properties.

Source:

spawned(entity)

Handles entity after spawning, useful for positioning, starting behavior, etc.
- links entity as a spawned entity to this spawner
- repositions entity based on spawning properties of this spawner

Parameters:
Name Type Description
entity ig.EntityExtended entity that has been spawned.
Source:

spawnNext(entity) → {ig.EntityExtended}

Spawns next entity of spawning entity if possible.

Parameters:
Name Type Argument Description
entity ig.EntityExtended <optional>
entity to force spawn (i.e. ignore pool and count)
Source:
Returns:
{ ig.EntityExtended } entity spawned

unlinkSpawned()

Removes attachments between spawner and spawned.
- removes hooks to ig.EntityExtended#onRemoved signal
- removes 'spawner' property from entity

Source:

unpause()

Source:

unspawn(entity, silent)

Returns an entity to the spawning pool. IMPORTANT: if entity is not killed, will kill instead.

Parameters:
Name Type Argument Default Description
entity ig.EntityExtended entity to kill and return to pool
silent Boolean <optional>
ig.Spawner.unspawnSilently whether to despawn silently (i.e. no death animation).
Source:

update()

Updates spawner and handles spawning next if spawning over a duration.

Source: