ecspresso
    Preparing search index...

    Getting Started

    npm install ecspresso
    
    import ECSpresso from 'ecspresso';

    // 1. Define your component types
    interface Components {
    position: { x: number; y: number };
    velocity: { x: number; y: number };
    health: { value: number };
    }

    // 2. Create a world using the builder — types are inferred automatically
    const world = ECSpresso.create()
    .withComponentTypes<Components>()
    .build();

    // 3. Add a movement 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. Create entities
    const player = world.spawn({
    position: { x: 0, y: 0 },
    velocity: { x: 10, y: 5 },
    health: { value: 100 }
    });

    // 5. Run the game loop
    world.update(1/60);