@browserbyte/ecs
TypeScript icon, indicating that this package has built-in type declarations

1.0.8 • Public • Published

BrowserByte/ECS

Simple Entity Component System written in TypeScript.

Features

  • Fully written in TypeScript
  • Fully tested
  • Large focus on performance, handles thousands of entities without a problem.
  • Simple API
  • Component serialization and deserialization (for networking or storage purposes).
  • Used in multiple real-world applications.

Installation

Using npm:

$ npm install @browserbyte/ecs

Using yarn:

$ yarn add @browserbyte/ecs

Example usage

Below is a small example on how you could use this package, there are multiple ways to accomplish certain things.

// Create a component class
class TestComponent extends Component
{
    public testValue: number;

    constructor(testValue: number) {
        super();

        this.testValue = testValue;
    }

    allowMultiple = true;
}

// Create a system
class TestSystem extends System
{
    private _testFamily!: Family;

    onAttach(engine: Engine): void {
        this._testFamily = engine.createFamily([], [ TestComponent ], []);
    }

    update(delta: number): void {
        this._testFamily.entities.forEach(entity => {
            const testComponent = testTwoEntity.getComponent(TestComponent);
            testComponent.testValue += 1;
        });
    }
}

// Create the ECS and attach a system
const ECS = new Engine(TestSystem);

// Create an entity with a component
const testEntity = ECS.createEntity(new TestComponent(2));

// Start the update loop
setInterval(() => ECS.update(deltaTime), 1000);

See the /examples folder for more example usages.

Resources / Inspirations

Readme

Keywords

none

Package Sidebar

Install

npm i @browserbyte/ecs

Weekly Downloads

10

Version

1.0.8

License

SEE LICENSE IN LICENSE

Unpacked Size

193 kB

Total Files

76

Last publish

Collaborators

  • ansien12