vdkuipb-ecs
TypeScript icon, indicating that this package has built-in type declarations

1.1.2 • Public • Published

ecs

Ecs is a simple Typescript library of a bare ecs implementation.

Installation

Use the package manager npm to install ecs.

npm install vdkuipb-ecs

Usage

import { Entity, System } from "vdkuipb-ecs"

export class RotationComponent {
    angle = 0;
}


class RotatorSystem extends System {

    protected getRequiredComponents() {
        return [ RotationComponent ]
    }

    protected entityInstantiated(entity: Entity): void {
        let rotation: RotationComponent = entity.getComponent(RotationComponent);
        rotation.angle = 50;
    }

    protected entityUpdate(entity: Entity, delta?: number): void {
        let rotation: RotationComponent = entity.getComponent(RotationComponent);
        rotation.angle += 1;

        console.log(rotation.angle);

        if (rotation.angle >= 100) {
            this.remove(entity);
        }
    }

    protected entityDestroyed(entity: Entity): void {
        console.log("removed: " + entity.id);
    }
}

var entity = new Entity();
entity.addComponent(PositionComponent);
entity.addComponent(RotationComponent);

var system = new RotatorSystem();
system.add(entity);

let prev = Date.now();
setInterval(() => {
    system.update(prev - Date.now());
    prev = Date.now();
}, 1000 / 10);

A better example can be found in the example folder.

Documentation

PlantUML model

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Lisence

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i vdkuipb-ecs

Weekly Downloads

1

Version

1.1.2

License

SEE LICENSE

Unpacked Size

23.7 kB

Total Files

26

Last publish

Collaborators

  • vdkuipb