API Documentation for: 1.0.1
Show:

platypus.components.EntityController Class

This component listens for input messages triggered on the entity and updates the state of any controller inputs it is listening for. It then broadcasts messages on the entity corresponding to the input it received.

Methods

'handle-controller'

()

On each handle-controller message, this component checks its list of actions and if any of their states are currently true or were true on the last call, that action message is triggered.

'pause-controls'

()

This message will stop the controller from triggering messages until "unpause-controls" is triggered on the entity.

'pointerdown'

(
  • value.event
)

Defined in 'pointerdown':173

This message triggers a new message on the entity that includes what button on the mouse was pressed: "mouse:left-button:down", "mouse:middle-button:down", or "mouse:right-button:down".

Parameters:

  • value.event DOM Event object

    This event object is passed along with the new message.

'pressmove'

(
  • value
)

Defined in 'pressmove':262

Updates joystick input if joystick is enabled.

Parameters:

  • value platypus.Data

    This event object is passed along with the joystick messages.

'pressup'

(
  • value.event
)

Defined in 'pressup':214

This message triggers a new message on the entity that includes what button on the mouse was released: "mouse:left-button:up", "mouse:middle-button:up", or "mouse:right-button:up".

Parameters:

  • value.event DOM Event object

    This event object is passed along with the new message.

'unpause-controls'

()

This message will allow the controller to trigger messages until "pause-controls" is triggered on the entity.

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.Component: 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.

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
Returns a string describing the component.

Returns:

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

Properties

controlMap

Object

Defined in controlMap:59

Use the controlMap property object to map inputs to messages that should be triggered. At least one control mapping should be included. The following are a few examples:

  {
                                                  "key:x": "run-left",
                                                  // This causes an "x" keypress to fire "run-left" on the entity. For a full listing of key names, check out the HandlerController component.
                                            
                                                  "button-pressed": "throw-block",
                                                  // custom input messages can be fired on this entity from other entities, allowing for on-screen input buttons to run through the same controller channel as other inputs.
                                            
                                                  "mouse:left-button"
                                                  // The controller can also handle mouse events on the entity if the entity's render component triggers mouse events on the entity (for example, the RenderSprite component).
                                              }

Default: {}

joystick

Object

Defined in joystick:79

Determines whether this entity should listen for mouse events to trigger directional events. Can be set simply to "true" to accept all joystick defaults.

  "joystick": {
                                                  "directions": 8, // Optional: 4, 8, or 16. Determines how many directions to broadcast. Default is 4 ("north", "east", "south", and "west").
                                                  "innerRadius": 30, // Optional. Number determining how far the mouse must be from the entity's position before joystick events should be triggered. Default is 0.
                                                  "outerRadius": 60 // Optional. Number determining how far the mouse can move away from the entity's position before the joystick stops triggering events. Default is Infinity.
                                              }

Default: null

paused

Boolean

Defined in paused:106

Whether input controls should be deactivated.

Default: false

stateMaps

Object

Defined in stateMaps:94

Available since 0.6.7

The stateMaps property can hold multiple control maps. Use this if certain controls should only be available for certain states. The controller finds the first valid state and falls back to the base controlMap as default if no matches are found.

Default: {}

Events

'*'

Defined in '*':444

Broadcasts active states using the JSON-defined message on each handle-controller message. Active states include pressed being true or released being true. If both of these states are false, the message is not broadcasted.

Event Payload:

  • message.pressed Boolean

    Whether the current input is active.

  • message.released Boolean

    Whether the current input was active last tick but is no longer active.

  • message.triggered Boolean

    Whether the current input is active but was not active last tick.

  • message.over Boolean

    Whether the mouse was over the entity when pressed, released, or triggered. This value is always false for non-mouse input messages.

'east'

Defined in 'east':344

If the soft joystick is enabled on this component, it will broadcast this directional message if the joystick is dragged due east.

Event Payload:

  • message DOM Event object

    The original pointer event object is passed along with the control message.

'east-northeast'

If the soft joystick is enabled on this component, it will broadcast this directional message if the joystick is dragged due east-northeast.

Event Payload:

  • message DOM Event object

    The original pointer event object is passed along with the control message.

'east-southeast'

If the soft joystick is enabled on this component, it will broadcast this directional message if the joystick is dragged due east-southeast.

Event Payload:

  • message DOM Event object

    The original pointer event object is passed along with the control message.

'joystick-orientation'

If the soft joystick is enabled on this component, this message will trigger to provide the current orientation of the joystick.

Event Payload:

  • orientation Object

    (number) - A number in radians representing the orientation of the joystick.

'joystick:down'

Defined in 'joystick:down':203

This event is triggered when there is an active touch in the joystick area.

Event Payload:

  • message DOM Event object

    The original pointer event object is passed along with the control message.

'joystick:up'

Defined in 'joystick:up':246

This event is triggered when there is an active touch is released from the joystick area.

Event Payload:

  • message DOM Event object

    The original pointer event object is passed along with the control message.

'mouse:mouse-left:down'

This component triggers the state of mouse inputs on the entity if a render component of the entity accepts mouse input.

Event Payload:

  • message DOM Event object

    The original mouse event object is passed along with the control message.

'mouse:mouse-left:up'

This component triggers the state of mouse inputs on the entity if a render component of the entity accepts mouse input (for example [[Render-Animation]]).

Event Payload:

  • message DOM Event object

    The original mouse event object is passed along with the control message.

'mouse:mouse-middle:down'

This component triggers the state of mouse inputs on the entity if a render component of the entity accepts mouse input (for example [[Render-Animation]]).

Event Payload:

  • message DOM Event object

    The original mouse event object is passed along with the control message.

'mouse:mouse-middle:up'

This component triggers the state of mouse inputs on the entity if a render component of the entity accepts mouse input (for example [[Render-Animation]]).

Event Payload:

  • message DOM Event object

    The original mouse event object is passed along with the control message.

'mouse:mouse-right:down'

This component triggers the state of mouse inputs on the entity if a render component of the entity accepts mouse input (for example [[Render-Animation]]).

Event Payload:

  • message DOM Event object

    The original mouse event object is passed along with the control message.

'mouse:mouse-right:up'

This component triggers the state of mouse inputs on the entity if a render component of the entity accepts mouse input (for example [[Render-Animation]]).

Event Payload:

  • message DOM Event object

    The original mouse event object is passed along with the control message.

'north'

Defined in 'north':320

If the soft joystick is enabled on this component, it will broadcast this directional message if the joystick is dragged due north.

Event Payload:

  • message DOM Event object

    The original pointer event object is passed along with the control message.

'north-northeast'

If the soft joystick is enabled on this component, it will broadcast this directional message if the joystick is dragged due north-northeast.

Event Payload:

  • message DOM Event object

    The original pointer event object is passed along with the control message.

'north-northwest'

If the soft joystick is enabled on this component, it will broadcast this directional message if the joystick is dragged due north-northwest.

Event Payload:

  • message DOM Event object

    The original pointer event object is passed along with the control message.

'northeast'

Defined in 'northeast':332

If the soft joystick is enabled on this component, it will broadcast this directional message if the joystick is dragged due northeast.

Event Payload:

  • message DOM Event object

    The original pointer event object is passed along with the control message.

'northwest'

Defined in 'northwest':404

If the soft joystick is enabled on this component, it will broadcast this directional message if the joystick is dragged due northwest.

Event Payload:

  • message DOM Event object

    The original pointer event object is passed along with the control message.

'south'

Defined in 'south':368

If the soft joystick is enabled on this component, it will broadcast this directional message if the joystick is dragged due south.

Event Payload:

  • message DOM Event object

    The original pointer event object is passed along with the control message.

'south-southeast'

If the soft joystick is enabled on this component, it will broadcast this directional message if the joystick is dragged due south-southeast.

Event Payload:

  • message DOM Event object

    The original pointer event object is passed along with the control message.

'south-southwest'

If the soft joystick is enabled on this component, it will broadcast this directional message if the joystick is dragged due south-southwest.

Event Payload:

  • message DOM Event object

    The original pointer event object is passed along with the control message.

'southeast'

Defined in 'southeast':356

If the soft joystick is enabled on this component, it will broadcast this directional message if the joystick is dragged due southeast.

Event Payload:

  • message DOM Event object

    The original pointer event object is passed along with the control message.

'southwest'

Defined in 'southwest':380

If the soft joystick is enabled on this component, it will broadcast this directional message if the joystick is dragged due southwest.

Event Payload:

  • message DOM Event object

    The original pointer event object is passed along with the control message.

'stop'

Defined in 'stop':253

This event is triggered to stop movement once the joystick is released.

'west'

Defined in 'west':392

If the soft joystick is enabled on this component, it will broadcast this directional message if the joystick is dragged due west.

Event Payload:

  • message DOM Event object

    The original pointer event object is passed along with the control message.

'west-northwest'

If the soft joystick is enabled on this component, it will broadcast this directional message if the joystick is dragged due west-northwest.

Event Payload:

  • message DOM Event object

    The original pointer event object is passed along with the control message.

'west-southwest'

If the soft joystick is enabled on this component, it will broadcast this directional message if the joystick is dragged due west-southwest.

Event Payload:

  • message DOM Event object

    The original pointer event object is passed along with the control message.