Skip to content

Spawning Entities

Entities are instances of one or more Components. To create entities, use the global engine.spawn function.

ts
import type { Component, SystemOnce } from '@vaguevoid/fiasco'
import { Components } from '../.fiasco/generated'

type Animal = Component<{
  speed: number
}>

function animalSpawner(): SystemOnce {
  // spawn an animal with a transform into the world once
  const id = engine.spawn([
    new Components.Transform(),
    new Components.Animal({ speed: 8 })
  ])
}

Spawning returns an entity ID which can be used later to despawn the same entity.