entityx-ts
v2.3.1
Published
ecs system for safex engine
Readme
entityx-ts
entityx-ts is an Entity Component System (ECS) library for TypeScript, designed for high performance and flexibility.
It is used in projects like safex-pixi for game and interactive application development.
Installation
npm install entityx-tsBasic Usage
1. Create an Entity
import { World } from 'entityx-ts';
const world = new World();
const entity = world.entities.create();2. Define Components
class Position {
constructor(public x: number, public y: number) {}
}
class Velocity {
constructor(public dx: number, public dy: number) {}
}3. Add Components to Entities
entity.assign(new Position(0, 0));
entity.assign(new Velocity(1, 1));4. Create Systems
class MovementSystem {
update(world: World) {
for (const entity of entities.entities_with_components(Position, Velocity)) {
const pos = entity.getComponent(Position);
const vel = entity.getComponent(Velocity);
pos.x += vel.dx;
pos.y += vel.dy;
}
}
}5. Run the World
function gameLoop() {
const movementSystem = world.systems.get(MovementSystem);
movementSystem.update(dt);
requestAnimationFrame(gameLoop);
}
gameLoop();Integration with safex-pixi
safex-pixi uses entityx-ts to manage game entities and components, enabling scalable and maintainable game logic.
Refer to safex-pixi for advanced usage and integration examples.
