Spawner¶
import { Spawner } from "encompass-ecs";
A Spawner is a subclass of Engine that provides a structure for a common pattern - reading a Message and creating a new Entity in response.
Spawners are defined by the Message type they track,
and the spawn
function they implement.
The first message type given in the @Reads
decorator is assumed to be the spawn message type.
Abstracts¶
-
Spawner:spawn
(message)¶ Arguments: - message (Message) – A message that has been read by the Spawner.
This callback is triggered when a Message of the specified prototype is produced.
Example¶
import { Engine, Message, Reads, Type } from "encompass-ecs";
import { CellComponent } from "game/components/cell";
import { SpawnCellMessage } from "game/messages/spawn_cell";
@Reads(SpawnCellMessage)
export class SpawnCellEngine extends Spawner {
public spawn(message: SpawnCellMessage) {
const cell_entity = this.create_entity();
const cell_component = cell_entity.add_component(CellComponent);
cell_component.i = message.i;
cell_component.j = message.j;
cell_component.alive = true;
}
}