Totally experimental, subject to at least one breaking API change, so think twice before you use this (for now). Built with browserify in mind.
npm install bindlestiff
var bs =var ticker =var manager = bsvar physical = bsvar controllable = bsvar Player = bsvar player =manager
Components define the behavior of your entities: for example, a
component could encapsulate all of your physics handling and a
component could take care of drawing the entity to the screen.
Components can set properties on their entities, or keep all of their scope in a closure. They can also react to events and attach tags to entity definitions.
Defines a component. You can optionally pass one or more tags as a string or array of strings - these are used to label entity definitions so that entities can be filtered by type by the manager.
Assigns an event listener to this component. The component itself won't
listen to this event, but any entities using this component will call
entity.trigger('event') is called.
Ensures that the entity definition this component is applied has been tagged
tag. If not, the component will throw an error. Note that order is
important here, you should specify your dependent component after its
Entities are the actual "things" in your game: bullets, enemies, players, blocks, etc. They're created by first defining them, then adding components and tags, and then instantiating them from the resulting class.
Creates a new
EntityDefinition. This is essentially a class - you can extend
it with components to add additional functionality, effectively getting
multiple inheritance with less boilerplate and overhead.
Attaches a component to the entity definition. Note that components are actually just functions, and this is just syntactical sugar.
Tags any entities with
Listen to events on these entities without having to create a new component.
After setting up the entity definition, you can create new entities as normal.
Instead of attaching methods to an entity definition, it's helpful to use
triggers. They're very similar to Node's
EventEmitter with the exception
of listeners being defined on the prototype rather then individual instances.
This way, you can trigger
draw on each entity every frame, and
hook into these events with multiple components.
A manager helps organise and filter your entities, and while it's not necessary to use it should make your game loop cleaner.
Creates a new manager.
Adds a new entity to the manager.
Removes an entity from the manager.
Returns an array of entities that are tagged with
Returns an array of entity definitions that are tagged with