EntityManager()

This class is used for managing all central objects of a game like game entities.

new EntityManager()

Constructs a new entity manager.

Author:

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.

Returns:
EntityManager -

A reference to this entity manager.

clear() → {EntityManager}

Clears the internal state of this entity manager.

Returns:
EntityManager -

A reference to this entity manager.

fromJSON(json) → {EntityManager}

Restores this instance from the given JSON object.

Parameters:
Name Type Description
json Object

The JSON object.

Returns:
EntityManager -

A reference to this entity manager.

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.

Returns:
GameEntity -

The found game entity.

processTrigger(trigger) → {EntityManager}

Processes a single trigger.

Parameters:
Name Type Description
trigger Trigger

The trigger to process.

Returns:
EntityManager -

A reference to this entity manager.

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.

Returns:
EntityManager -

A reference to this entity manager.

remove(entity) → {EntityManager}

Removes a game entity from this entity manager.

Parameters:
Name Type Description
entity GameEntity

The game entity to remove.

Returns:
EntityManager -

A reference to this entity manager.

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.

Returns:
EntityManager -

A reference to this entity manager.

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.

Returns:
EntityManager -

A reference to this entity manager.

updateEntity(entity, delta) → {EntityManager}

Updates a single entity.

Parameters:
Name Type Description
entity GameEntity

The game entity to update.

delta Number

The time delta.

Returns:
EntityManager -

A reference to this entity manager.

updateNeighborhood(entity) → {EntityManager}

Updates the neighborhood of a single game entity.

Parameters:
Name Type Description
entity GameEntity

The game entity to update.

Returns:
EntityManager -

A reference to this entity manager.