module.exports

platypus. module.exports

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.
        },

        "preload": ['image.png', 'sound.mp3']
        // assets that need to be loaded before this entity loads
    }

Constructor

new module.exports(definitionopt, instanceDefinitionopt, callbackopt, parentopt) → {Entity}

Source:
Parameters:
Name Type Attributes Description
definition Object <optional>

Base definition for the entity.

Name Type Attributes Description
components Object <optional>

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

id Object <optional>

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

properties Object <optional>

[definition.properties] 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.

Name Type Attributes Description
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.

parent Entity <optional>

Presets the parent of the entity so that the parent entity is available during component instantiation. Overrides parent in properties definitions.

Fires:
Returns:
Type:
Entity

Returns the new entity made up of the provided components.

Extends