GG-Entities
easy-to-use Entity-Component System for browsers and Node.js
Usage
const entityManager = // 1. Register Components const pos = entityManager const vel = entityManager // 2. Register Systems { for const entity of entities entityposx += entityvel * delta } entityManager { for const entity of entities console } entityManager // 3. Add an entity entityManager // 4. Run the systems entityManager // invokes all logic systems (movementSystem)entityManager // invokes all render systems (logSystem)
Features
- Easy to use
- Configurable
- 100% code coverage
- Fast [TODO: add benchmarks and comparisons to back this claim]
Examples
Docs
http://ggalansmithee.github.io/Entities/
Typings
There are no official typings (yet), but @ForsakenHarmony has provided a gist for TypeScript users.
FAQ / Gotchas
- Since a system is bound with the
EntityManager
as its context, a system must be a regular function (not an es6 arrow function)
Tips and tricks
- Using destructuring and computed properties
Accessing an entity's components in a system usually looks like this
{ for const entity of entities entityPOS_COMPONENTx += entityVEL_COMPONENTx * delta entityPOS_COMPONENTy += entityVEL_COMPONENTy * delta }
which can be a bit ugly, especially if your entity has a lot of components which are accessed multiple times. Using some ES6 (computed property keys) and ES7 (object spread) magic, we can make it a bit more concise:
{ for const entity: POS_COMPONENT: pos VEL_COMPONENT: vel of entities posx += velx * delta posy += vely * delta }
Get involved
-
Got questions or want to leave feedback? create an issue
-
Got improvements? Feel free to send a PR to the
dev
branch (don't forget to add tests)npm run build
builds the projectnpm run test
runs the test suite