API Documentation for: 0.11.8
Show:

platypus.components.EntityContainer Class

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

Methods

'*'

(
  • message
)

Defined in '*':157

Listens for specified messages and on receiving them, re-triggers them on child entities.

Parameters:

  • message Object

    Accepts a message object that it will include in the new message to be triggered.

'add-entity'

(
  • entity
  • [callback]
)

Defined in 'add-entity':119

This message will added the given entity to this component's list of entities.

Parameters:

  • entity platypus.Entity

    This is the entity to be added as a child.

  • [callback] Function optional

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

'remove-entity'

(
  • entity
)

Defined in 'remove-entity':130

On receiving this message, the provided entity will be removed from the list of child entities.

Parameters:

addEntity

(
  • newEntity
  • [callback]
)
platypus.Entity

Defined in addEntity:303

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.

Parameters:

  • 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.

    • [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.

Returns:

platypus.Entity:

The entity that was just added.

addEventListener

(
  • event
  • callback
)
Function private
This method adds an event listener to the entity.

Parameters:

  • event String
    The event that this component should listen for.
  • callback Function
    The handler for the event.

Returns:

Function: handler A reference to the bound handler.

addMethod

(
  • name
  • func
)
private
This method adds a method to the entity.

Parameters:

  • name String
    The name of the method. For example, if name is "turnYellow", the method is accessible on the entity as entity.turnYellow().
  • func Function
    The function describing the method.

destroy

() private

Inherited from platypus.Messenger but overwritten in destroy:54

This method cleans up listeners and methods that this component added to the entity. It should never be called by the component itself. Call this.owner.removeComponent(this) instead.

getAssetList

(
  • definition
  • properties
  • defaultProperties
)
Array
This method can be overwritten to provide the list of assets this component requires. This method is invoked when the list of game scenes is created to determine assets for each scene.

Parameters:

  • definition Object
    The definition for the component.
  • properties Object
    The properties of the Entity.
  • defaultProperties Object
    The default properties of the Entity.

Returns:

Array: A list of the necessary assets to load.

getLateAssetList

(
  • data
)
Array
This method can be overwritten to provide the list of assets this component requires. This method is invoked when the list of game scenes is created to determine assets for each scene.

Parameters:

  • data Object
    Scene data that affects the list of assets.

Returns:

Array: A list of the necessary assets to load.

getMessageIds

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

Returns:

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

removeEventListener

(
  • event
  • callback
)
private
This method removes an event listener from the entity.

Parameters:

  • event String
    The event for which to remove a listener.
  • callback Function
    The listener to remove. If not supplied, all event listeners for the provided event are removed.

removeEventListeners

(
  • [listeners]
)
private
This method removes multiple event listeners from the entity.

Parameters:

  • [listeners] Array optional
    The list of listeners to remove. If not supplied, all event listeners are removed.

removeMethod

(
  • name
)
private
This method removes a method from the entity.

Parameters:

  • name String
    The name of the method to be removed.

toJSON

() Object

Inherited from platypus.Component: toJSON:45

Available since 0.11.0

Returns a JSON object describing the component.

Returns:

Object: Returns a JSON definition that can be used to recreate the component.

toString

() String

Inherited from platypus.Messenger but overwritten in toString:35

Returns a string describing the component.

Returns:

String: Returns the component type as a string of the form "[Component ComponentType]".

trigger

(
  • event
  • value
  • debug
)
Number

Inherited from platypus.Messenger: trigger:32

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 {}

Parameters:

  • 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:

Number: The number of handlers for the triggered message.

triggerEvent

(
  • event
  • [value]
)
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](http://springroll.io/SpringRoll/docs/classes/springroll.EventDispatcher.html#method_trigger), but uses alternative Array methods to alleviate excessive GC.

Parameters:

  • event String
    This is the message to process.
  • [value] optional
    This is a message object or other value to pass along to event handler.
    • [debug] Boolean optional

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

Returns:

Number: The number of handlers for the triggered message.

Properties

childEvents

Array

Defined in childEvents:64

An Array listing messages that are triggered on the entity and should be triggered on the children as well.

Default: []