new EntityManager()
Constructs a new entity manager.
Members
-
readonly entities :Array.<GameEntity>
-
A list of game entities.
-
nullable spatialIndex :CellSpacePartitioning
-
A reference to a spatial index.
- Default Value:
- null
Methods
-
add(entity) → {EntityManager}
-
Adds a game entity to this entity manager.
Parameters:
Name Type Description entity
GameEntity The game entity to add.
-
clear() → {EntityManager}
-
Clears the internal state of this entity manager.
-
fromJSON(json) → {EntityManager}
-
Restores this instance from the given JSON object.
Parameters:
Name Type Description json
Object The JSON object.
-
getEntityByName(name) → {GameEntity}
-
Returns an entity by the given name. If no game entity is found, null is returned. This method should be used once (e.g. at GameEntity#start) and the result should be cached for later use.
Parameters:
Name Type Description name
String The name of the game entity.
-
processTrigger(trigger) → {EntityManager}
-
Processes a single trigger.
Parameters:
Name Type Description trigger
Trigger The trigger to process.
-
registerType(type, constructor) → {EntityManager}
-
Registers a custom type for deserialization. When calling EntityManager#fromJSON the entity manager is able to pick the correct constructor in order to create custom game entities.
Parameters:
Name Type Description type
String The name of the entity type.
constructor
function The constructor function.
-
remove(entity) → {EntityManager}
-
Removes a game entity from this entity manager.
Parameters:
Name Type Description entity
GameEntity The game entity to remove.
-
sendMessage(sender, receiver, message, delay, data) → {EntityManager}
-
Interface for game entities so they can send messages to other game entities.
Parameters:
Name Type Description sender
GameEntity The sender.
receiver
GameEntity The receiver.
message
String The actual message.
delay
Number A time value in millisecond used to delay the message dispatching.
data
Object An object for custom data.
-
toJSON() → {Object}
-
Transforms this instance into a JSON object.
Returns:
Object -The JSON object.
-
update(delta) → {EntityManager}
-
The central update method of this entity manager. Updates all game entities and delayed messages.
Parameters:
Name Type Description delta
Number The time delta.
-
updateEntity(entity, delta) → {EntityManager}
-
Updates a single entity.
Parameters:
Name Type Description entity
GameEntity The game entity to update.
delta
Number The time delta.
-
updateNeighborhood(entity) → {EntityManager}
-
Updates the neighborhood of a single game entity.
Parameters:
Name Type Description entity
GameEntity The game entity to update.