EntityContainer

platypus.components. EntityContainer

new EntityContainer()

This component allows the entity to contain child entities. It will add several methods to the entity to manage adding and removing entities.

Source:
Listens to Events:

Extends

Members

destroyed :Boolean

This read-only property shows whether this Messenger is destroyed.

Properties:
Name Type Description
destroyed
Inherited From:
Default Value:
  • false
Source:
Type:
  • Boolean

Methods

addEntity(newEntity, callbackopt) → {platypus.Entity}

This method adds an entity to the owner's group. If an entity definition or a reference to an entity definition is provided, the entity is created and then added to the owner's group.

Source:
Parameters:
Name Type Attributes Description
newEntity platypus.Entity | Object | String

Specifies the entity to add. If an object with a "type" property is provided or a String is provided, this component looks up the entity definition to create the entity.

Name Type Attributes Description
type String <optional>

If an object with a "type" property is provided, this component looks up the entity definition to create the entity.

properties Object <optional>

A list of key/value pairs that sets the initial properties on the new entity.

callback function <optional>

A function to run once all of the components on the Entity have been loaded.

Fires:
Returns:
Type:
platypus.Entity

The entity that was just added.

destroy()

This method relinguishes Messenger properties

Inherited From:
Source:

getEntitiesByType(type) → {Array}

Returns a list of entities of the requested type.

Source:
Parameters:
Name Type Description
type String
Returns:
Type:
Array

getEntityById(id) → {Entity}

Gets an entity in this layer by its Id. Returns null if not found.

Source:
Parameters:
Name Type Description
id String
Returns:
Type:
Entity

getMessageIds() → {Array}

This method returns all the messages that this entity is concerned about.

Inherited From:
Source:
Returns:
Type:
Array

An array of strings listing all the messages for which this Messenger has handlers.

off(name, callback)

Remove the event listener

Inherited From:
Source:
Parameters:
Name Type Description
name String

The type of event; if no name is specifed remove all listeners.

callback function

The listener function.

on(name, callback)

Add an event listener. The parameters for the listener functions depend on the event.

Inherited From:
Source:
Parameters:
Name Type Description
name String

The type of event.

callback function

The callback function when event is triggered.

removeEntity(entity) → {Entity}

Removes the provided entity from the layer and destroys it. Returns false if the entity is not found in the layer.

Source:
Parameters:
Name Type Description
entity Entity
Fires:
Returns:
Type:
Entity

toString()

Returns a string describing the Messenger as "[Messenger object]".

Inherited From:
Source:
Returns:

String

trigger(event, value, debug) → {number}

This method is used by both internal components and external entities to trigger messages. When triggered, Messenger checks through bound handlers to run as appropriate. This handles multiple event structures: "", [], and {}

Inherited From:
Source:
Parameters:
Name Type Description
event String | Array | Object

This is the message(s) to process. This can be a string, an object containing an "event" property (and optionally a "message" property, overriding the value below), or an array of the same.

value *

This is a message object or other value to pass along to event handler.

debug boolean

This flags whether to output message contents and subscriber information to the console during game development. A "value" object parameter (above) will also set this flag if value.debug is set to true.

Returns:
Type:
number

The number of handlers for the triggered message.

triggerEvent(event, valueopt) → {number}

This method is used by both internal components and external entities to trigger messages on this entity. When triggered, entity checks through bound handlers to run as appropriate. This method is identical to Spring Roll's EventDispatcher.trigger, but uses alternative Array methods to alleviate excessive GC.

Inherited From:
Source:
Parameters:
Name Type Attributes Description
event String

This is the message to process.

value * <optional>

This is a message object or other value to pass along to event handler.

Name Type Attributes Description
debug boolean <optional>

This flags whether to output message contents and subscriber information to the console during game development.

Returns:
Type:
number

The number of handlers for the triggered message.

triggerEventOnChildren(event, message, debug)

Triggers a single event on the child entities in the layer.

Source:
Parameters:
Name Type Description
event *
message *
debug *

triggerOnChildren(event, message, debug)

Triggers one or more events on the child entities in the layer. This is unique from triggerEventOnChildren in that it also accepts an Array to send multiple events.

Source:
Parameters:
Name Type Description
event *
message *
debug *