(pronounced "ex-presso")
v0.12.3
A type-safe, modular ECS framework for TypeScript
import ECSpresso from 'ecspresso';
interface Components {
position: { x: number; y: number };
velocity: { x: number; y: number };
health: { value: number };
}
const world = ECSpresso.create()
.withComponentTypes<Components>()
.build();
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;
}
});
world.spawn({
position: { x: 0, y: 0 },
velocity: { x: 10, y: 5 },
health: { value: 100 },
});
world.update(1 / 60);