👾 bitECS 👾
Tiny, data-driven, high performance ECS library written using JavaScript TypedArrays.
Features
<3kb
gzipped- Zero dependencies
- Node or Browser
- Fast
Install
npm i bitecs
Example
import World from 'bitecs'
const world = World()
world.registerComponent('POSITION', { x: 'float32', y: 'float32' })
world.registerComponent('VELOCITY', { vx: 'int8', vy: 'int8', speed: 'uint16' })
world.registerSystem({
name: 'MOVEMENT',
components: ['POSITION', 'VELOCITY'],
update: (position, velocity) => eid => {
position.x[eid] += velocity.vx[eid] * velocity.speed[eid]
position.y[eid] += velocity.vy[eid] * velocity.speed[eid]
}
})
const eid = world.addEntity()
world.addComponent('POSITION', eid, { x: 100, y: 100 })
world.addComponent('VELOCITY', eid, { vx: 1, vy: -1, speed: 100 })
setInterval(() => {
world.step()
}, 1000 / 30)
const loop = () => {
world.step()
requestAnimationFrame(loop)
}
loop()
Full documentation and feature rich examples can be found here.