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

3.2.2 • Public • Published

CURBL-ECS

curbl-ecs is a lightweight Entity Component.

Example

  • Creating a Component
import { ECS } from '@curbl/ecs';

const ecs = new ECS();

@ecs.Component('Position') 
class PositionComponent {
    x: number = 0;
    y: number = 0;
}
  • Adding a Entity with components
const ecs = new ECS();
const entity = ecs.addEntity(new PositionComponent());
  • Create entity and add Component
const ecs = new ECS();
const entity = ecs.addEntity();
entity.add(new PositionComponent());
  • Get Component from Entity
entity.get<PositionComponent>('Position').x = 42;
  • Creating a System
const ecs = new ECS();

@ecs.System('Position')
export class MySystem {

    setUp(): void {
        //Called when the System is created/added to the ECS 
    }

    tearDown(): void {
        //Called when the System is removed from the ECS
    }

    update(): void {
        const entities = this.entities();
        for (let i = 0, entity: Entity; entity = entities[i]; i++) {
            //Do stuff with the entities
        }
    }
}

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
3.2.21latest

Version History

VersionDownloads (Last 7 Days)Published
3.2.21
3.2.11
3.2.1-91
3.2.1-81
3.2.1-71
3.2.1-61
3.2.1-51
3.2.1-40
3.2.1-30
3.2.1-20
3.2.0-00
3.1.00
3.0.00
2.2.11
2.2.00
2.1.20

Package Sidebar

Install

npm i @curbl/ecs

Weekly Downloads

8

Version

3.2.2

License

MIT

Unpacked Size

189 kB

Total Files

22

Last publish

Collaborators

  • nan0c