@javelin/ecs
v1.0.0-alpha.13
Published
A TypeScript/JavaScript Entity-Component System
Downloads
1,254
Maintainers
Readme
@javelin/ecs
Javelin is an implementation of ECS, a popular architecture for building games with dynamic entity behavior.
Join us on Discord!
Docs
Visit https://javelin.dev
Installation
npm i @javelin/ecs
Quick Start
import * as j from "@javelin/ecs"
// define entity data
let Pos = j.value({x: "number", y: "number"})
let Vel = j.value({x: "number", y: "number"})
// create an app
let app = j
.app()
// initialize entities (discrete game units)
.addInitSystem(world => {
let origin = {x: 0, y: 0}
world.create(j.type(Pos, Vel), origin, {x: 0, y: -1})
})
// find entities by type
.addSystem(world => {
world.query(j.type(Pos, Vel)).each((entity, pos, vel) => {
pos.x += vel.x
pos.y += vel.y
})
})
// call all registered systems
.step()