1.0.8 • Published 4 years ago

@browserbyte/ecs v1.0.8

Weekly downloads
1
License
SEE LICENSE IN LI...
Repository
-
Last release
4 years ago

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

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago