Crafty.s()

Registers a system.

Events

SystemLoaded [system object = {obj}]
When the system has initialized itself
SystemDestroyed [system object = {obj}]
Right before the system is destroyed
void Crafty.s(String name, Obj template[, Obj options][, Boolean lazy])

Register a system

name

The name of the system

template

an object whose methods and properties will be copied to the new system

options

an object whose properties will be deep copied to the new system's options property

lazy

a flag that indicates whether the system should be initialized right away or the first time it is referenced

System Crafty.s(String name)

Access the named system

name

The system to return

[Returns]

The referenced system. If the system has not been initialized, it will be before it is returned.

Objects which handle entities might want to subscribe to the event system without being entities themselves. When you declare a system with a template object, all the methods and properties of that template are copied to a new object. This new system will automatically have the following event related methods, which function like those of components: .bind(), unbind(), trigger(), one(), uniqueBind(), destroy(). Much like components, you can also provide init() and remove() methods, as well as an events parameter for automatically binding to events.

Note: The init() method is for setting up the internal state of the system -- if you create entities in it that then reference the system, that'll create an infinite loop.