1.1.2 • Published 5 years ago

vdkuipb-ecs v1.1.2

Weekly downloads
32
License
SEE LICENSE
Repository
github
Last release
5 years ago

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

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.4.0

5 years ago