ECSpresso

(pronounced "ex-presso")

v0.12.3

A type-safe, modular ECS framework for TypeScript

Quick Start

npm install ecspresso
1 — Define components
import ECSpresso from 'ecspresso';

interface Components {
  position: { x: number; y: number };
  velocity: { x: number; y: number };
  health: { value: number };
}
2 — Create a world
const world = ECSpresso.create()
  .withComponentTypes<Components>()
  .build();
3 — Add a system
world.addSystem('movement')
  .addQuery('moving', { with: ['position', 'velocity'] })
  .setProcess(({ queries, dt }) => {
    for (const entity of queries.moving) {
      entity.components.position.x += entity.components.velocity.x * dt;
      entity.components.position.y += entity.components.velocity.y * dt;
    }
  });
4 — Spawn entities
world.spawn({
  position: { x: 0, y: 0 },
  velocity: { x: 10, y: 5 },
  health: { value: 100 },
});
5 — Run
world.update(1 / 60);