API Documentation for: 0.11.8
Show:

platypus.Entity Class

Extends Messenger
Defined in: platypus.Entity:1
Module: platypus

The Entity object acts as a container for components, facilitates communication between components and other game objects, and includes properties set by components to maintain a current state. The entity object serves as the foundation for most of the game objects in the platypus engine.

JSON Definition Example

{
                            "id": "entity-id",
                            // "entity-id" becomes entity.type once the entity is created.
                         
                            "components": [
                            // This array lists one or more component definition objects
                         
                                {"type": "example-component"}
                               // The component objects must include a "type" property corresponding to a component to load, but may also include additional properties to customize the component in a particular way for this entity.
                            ],
                         
                            "properties": {
                            // This object lists properties that will be attached directly to this entity.
                         
                                "x": 240
                                // For example, x becomes entity.x on the new entity.
                            }
                        }

Constructor

platypus.Entity

(
  • [definition]
  • [instanceDefinition]
  • [callback]
)
Entity

Defined in platypus.Entity:1

Parameters:

  • [definition] Object optional

    Base definition for the entity.

    • [id] Object optional

      This declares the type of entity and will be stored on the Entity as entity.type after instantiation.

    • [components] Object optional

      This lists the components that should be attached to this entity.

    • [properties] [definition.properties] Object optional

      This is a list of key/value pairs that are added directly to the Entity as entity.key = value.

  • [instanceDefinition] Object optional

    Specific instance definition including properties that override the base definition properties.

    • [properties] Object optional

      This is a list of key/value pairs that are added directly to the Entity as entity.key = value.

  • [callback] Function optional

    A function to run once all of the components on the Entity have been loaded. The first parameter is the entity itself.

Returns:

Entity:

Returns the new entity made up of the provided components.

Methods

addComponent

(
  • component
)
platypus.Component

Defined in addComponent:187

Attaches the provided component to the entity.

Parameters:

Returns:

platypus.Component:

Returns the same object that was submitted.

destroy

()

Defined in destroy:265

This method removes all components from the entity.

getAssetList

(
  • definition
  • properties
)
Array

Defined in getAssetList:291

Returns all of the assets required for this Entity. This method calls the corresponding method on all components to determine the list of assets.

Parameters:

  • definition Object

    The definition for the Entity.

  • properties Object

    Properties for this instance of the Entity.

Returns:

Array:

A list of the necessary assets to load.

getLateAssetList

(
  • definition
  • data
)
Array

Returns all of the assets required for this Entity. This method calls the corresponding method on all components to determine the list of assets.

Parameters:

  • definition Object

    The definition for the Entity.

  • data Object

    Scene data that affects asset list.

Returns:

Array:

A list of the necessary assets to load.

removeComponent

(
  • component
)
Component

Defined in removeComponent:208

Removes the mentioned component from the entity.

Parameters:

  • component Component

    Must be a [[Component]] attached to the entity.

Returns:

Component:

Returns the same object that was submitted if removal was successful; otherwise returns false (the component was not found attached to the entity).

setProperty

(
  • properties
)

Defined in setProperty:249

This method sets one or more properties on the entity.

Parameters:

  • properties Object

    A list of key/value pairs to set as properties on the entity.

toJSON

(
  • includeComponents
)
Object

Defined in toJSON:150

Available since 0.11.0

Returns a JSON object describing the entity.

Parameters:

  • includeComponents Boolean

    Whether the returned JSON should list components. Defaults to false to condense output since components are generally defined in platypus.game.settings.entities, but may be needed for custom-constructed entities not so defined.

Returns:

Object:

Returns a JSON definition that can be used to recreate the entity.

toString

() String

Defined in toString:140

Returns a string describing the entity.

Returns:

String:

Returns the entity type as a string of the form "[Entity entity-type]".

Events

component-added

Defined in component-added:197

The entity triggers component-added on itself once a component has been attached, notifying other components of their peer component.

Event Payload:

component-removed

The entity triggers component-removed on itself once a component has been removed, notifying other components of their peer component's removal.

Event Payload:

  • component Component

    The removed component.

    • type String

      The type of component.

load

Defined in load:120

The entity triggers load on itself once all the properties and components have been attached, notifying the components that all their peer components are ready for messages.