A 1kb entity component system, designed for js13k.
- Tiny: weighs about one kilobyte gzipped
This project uses node and npm. Go check them out if you don't have them locally installed.
$ npm install js13k-ecs
Then with a module bundler like rollup or webpack, use as you would anything else:
// using ES6 modules
import ecs from 'js13k-ecs';
// using CommonJS modules
var ecs = require('js13k-ecs');
The UMD build is also available on unpkg:
<script src="https://unpkg.com/js13k-ecs/dist/ecs.umd.js"></script>
You can find the library on window.ecs
.
See example folder. Live example
Registers components for use by the library. Components must be classes or constructor functions. No other requirements are imposed on the components. Note that there is currently a limit of 32 registered components.
Adds systems for use by the library. Systems must be instances of classes or objects. Systems must implement the update
method.
Creates the entity with the specified id
. If id
is not specified, serial numbers starting with 1 are generated and encoded in base36. Returns the created entity.
Returns the entity with the specified id or undefined
if it is not present.
Returns a selection of entities that have the specified set of components. The sample is updated real-time and always relevant.
The selector has the length
property, which stores the number of entities in the sample and the iterate(fn)
method, with which you can loop through all entities.
Successively calls update
methods on all systems, passing them the delta
parameter. Returns the object that contains the duration of the execution of the systems.
Adds the components to the entity.
Removes components of the Components
class from the entity. Calls the destructor
method of each component if it is present.
Returns true if the entity has a component of the Component
class and false otherwise.
Returns a component of the Component
class or undefined
if it is not present.
Removes the entity from all selectors and sets its id
to zero. Calls the destructor
method of each component if it is present.