new Engine()
Extends
Members
-
systems :Array
-
Array of all the System in the Engine. You shouldn't edit this array directly, use Engine#addSystem and Engine#removeSystem instead.
Type:
- Array
Methods
-
addEntity(entity)
-
Adds an Entity to the Engine.
Parameters:
Name Type Description entity
Entity An Entity to add
Fires:
-
addSystem(key, system)
-
Adds the System to the Engine. The System will be triggered when the Engine#update is called. This will trigger System#add.
Parameters:
Name Type Description key
String The System's string key
system
System The System to add
-
c(key, constructor)
-
Registers a Component type to the Engine.
Parameters:
Name Type Description key
String Component's string key.
constructor
function Component's constructor.
-
createEntity() → {Entity}
-
Creates an empty Entity and adds to the Engine.
Fires:
Returns:
an empty Entity.
- Type
- Entity
-
createSystem(key) → {SystemBuilder}
-
Returns a new SystemBuilder associated the Engine.
Parameters:
Name Type Description key
String The System's string key to use.
Returns:
A new SystemBuilder
- Type
- SystemBuilder
-
deserialize(serialized)
-
Deserializes the Engine object and places on provided engine. The provided Engine object should be clean; it shouldn't contain any Entity object. But it can contain pre-defined Components and Systems. Note that systems won't be included in serialized object, so user should load the systems on their own.
Parameters:
Name Type Description serialized
Object Engine object
-
e()
-
Executes Entity related functions by its arguments.
If no argument is provided, it returns new Entity. If a number is provided, it returns a Entity with that ID. If an object is provided, it returns new Entity populated with the template. Otherwise, it returns an array of Entity having provided list components.
-
emit(event)
-
Emits the event. This will trigger all the listener with that event type. You can supply listener function's arguments by appending arguments after the 'event' parameter.
Parameters:
Name Type Description event
String The name of the event.
args...
Arguments to supply to listeners.
- Inherited From:
- Source:
-
getComponentBit(key)
-
Returns Component type's unique ID in the Engine. This unique ID is used in BitSet's bit position. This will call Engine#registerComponent if needed.
Parameters:
Name Type Description key
String Component's string key.
Returns:
the Component's unique ID.
-
getComponentConstructor(key)
-
Returns Component's constructor registered in the Engine/
Parameters:
Name Type Description key
String Component's string key.
Returns:
the Component's constructor.
-
getComponentGroup(entities) → {ComponentGroup}
-
Searches ComponentGroup by its array.
Parameters:
Name Type Description entities
Array An array of ComponentGroup
Returns:
The ComponentGroup linked with the array
- Type
- ComponentGroup
-
getComponentName(key)
-
Returns Component type's key by its unique ID.
Parameters:
Name Type Description key
Number Component's unique ID
Returns:
the Component's string key.
-
getComponentsBitSet(components) → {BitSet}
-
Returns a BitSet holding combination of Components type's unique ID.
Parameters:
Name Type Description components
Array An array holding Component keys.
Returns:
A BitSet holding combination of Components.
- Type
- BitSet
-
getEntities() → {Array}
-
Returns an array of Entity. It shouldn't be edited since the Engine uses it directly.
Returns:
An array holding Entity
- Type
- Array
-
getEntitiesFor(componentGroup) → {Array}
-
Returns an array having Entity matching ComponentGroup's criteria. The array will keep updated, so you can call this method only once and check its contents if needed. It's an alias function to Engine#registerComponentGroup
Parameters:
Name Type Description componentGroup
ComponentGroup The ComponentGroup
- Source:
- See:
Fires:
Returns:
An array holding Entity matching its criteria
- Type
- Array
-
getEntity(id) → {Entity}
-
Returns an Entity with given ID. This will return null if it can't be found.
Parameters:
Name Type Description id
Number An ID to find the Entity
Returns:
The entity with given ID
- Type
- Entity
-
getSystem(key) → {System}
-
Returns the System registered to the Engine.
Parameters:
Name Type Description key
String The System's string key
Returns:
The system registered to the Engine
- Type
- System
-
listeners(event) → {Array}
-
Returns the array of listeners with specified event type.
Parameters:
Name Type Description event
String The name of the event.
- Inherited From:
- Source:
Returns:
An array holding event listeners.
- Type
- Array
-
obtainEntityId() → {Number}
-
Returns a new Entity ID to use. This changes its value each time it's called.
Returns:
An integer that is used for Entity's ID
- Type
- Number
-
on(event, listener)
-
Registers a listener.
Parameters:
Name Type Description event
String The name of the event.
listener
function The function to be triggered.
- Inherited From:
- Source:
-
once(event, listener)
-
Registers a one-time listener. The listener will be removed after being triggered once.
Parameters:
Name Type Description event
String The name of the event.
listener
function The function to be triggered.
- Inherited From:
- Source:
-
registerComponent(key, constructor)
-
Registers a Component type to the Engine.
Parameters:
Name Type Description key
String Component's string key.
constructor
{Function] - Component's constructor.
-
registerComponentGroup(componentGroup) → {Array}
-
Registers the ComponentGroup to the Engine. Engine will check if an Entity matches ComponentGroup's criteria every time when a Entity is added or removed.
Parameters:
Name Type Description componentGroup
ComponentGroup The ComponentGroup to register
Fires:
Returns:
An array holding Entity matching its criteria
- Type
- Array
-
removeAllEntities()
-
Removes all Entity from the Engine.
Fires:
-
removeAllListeners(event)
-
Removes all the listener with specified event type. If event parameter is not set, it will remove all the listener of all types.
Parameters:
Name Type Argument Description event
String <optional>
The name of the event.
- Inherited From:
- Source:
-
removeEntity(entity)
-
Removes an Entity from the Engine.
Parameters:
Name Type Description entity
Entity An Entity to remove
Fires:
-
removeListener(event, listener)
-
Removes the listener.
Parameters:
Name Type Description event
String The name of the event.
listener
function The function to be removed.
- Inherited From:
- Source:
-
removeSystem(key)
-
Removes the System from the Engine. This will trigger System#remove.
Parameters:
Name Type Description key
String The System's string key to remove.
-
s()
-
Executes System related functions by its arguments.
If a key is provided and the Engine doesn't have a system with that key, it returns a SystemBuilder. If a key is provided and the Engine has a system with that key, it returns that system. If a key is provided and a system is provided, it registers the system.
-
<private> sortSystems()
-
Sorts the System array to match their priority.
-
toJSON() → {Object}
-
Serializes the Engine object. Note that systems won't be included in serialized object, so user should load the systems on their own.
Returns:
serialized Engine object
- Type
- Object
-
update()
-
An update function called by every tick of the game.
-
<private> updateComponentGroup(entity)
-
Updates the Entity to find if it matches ComponentGroups' criteria.
Parameters:
Name Type Description entity
Entity the Entity to update
- Source:
- See: