API Documentation for: 0.11.8
Show:

platypus.components.Motion Class

This component works in tandem with the Mover component by adding a vector of motion to the entity. This component is typically created by Mover and doesn't need to be added separately.

Methods

'control-acceleration'

(
  • control
)

Defined in 'control-acceleration':244

Available since 0.6.8

This event controls whether the acceleration is active or inactive.

Parameters:

  • control Object | Boolean

    If true, this motion becomes active. If false or {pressed: false}, the motion becomes inactive.

'control-velocity'

(
  • control
)

Defined in 'control-velocity':213

Available since 0.6.8

This event controls whether this velocity is active or inactive.

Parameters:

  • control Object | Boolean

    If true, this motion becomes active. If false or {pressed: false}, the motion becomes inactive.

'instant-begin'

()

Defined in 'instant-begin':286

Available since 0.6.7

This event triggers the beginning of an instant motion.

'instant-end'

()

Defined in 'instant-end':296

Available since 0.6.7

This event triggers the end of an instant motion.

'instant-motion'

(
  • control
)

Defined in 'instant-motion':275

Available since 0.6.7

This event triggers an instant motion.

Parameters:

  • control Object | Boolean

    If true, this motion becomes active. If false or {triggered: false}, the motion becomes inactive.

'set-motion'

(
  • motion
)

Defined in 'set-motion':306

Available since 0.6.8

This event modifies the properties of this Motion.

Parameters:

  • motion Object

    A list of key/value pairs corresponding to motion values.

    • [maxMagnitude] Number optional

      A value describing the maximum velocity or acceleration the motion vector can exert on the Entity.

'start-acceleration'

()

Defined in 'start-acceleration':265

Available since 0.6.8

This event sets the acceleration to active.

'start-velocity'

()

Defined in 'start-velocity':234

Available since 0.6.8

This event sets the velocity to active.

'stop-acceleration'

()

Defined in 'stop-acceleration':255

Available since 0.6.8

This event sets the acceleration to inactive.

'stop-velocity'

()

Defined in 'stop-velocity':224

Available since 0.6.8

This event sets the velocity to inactive.

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

acceleration

platypus.Vector | Array | Number

Defined in acceleration:83

Available since 0.6.8

A vector, Array, or number specifying the acceleration of the motion. Numbers apply magnitude along the x-axis. Arrays map to [x, y, z] on the vector.

Default: Vector(0, 0, 0)

activeAcceleration

Boolean

Whether this motion should apply acceleration to the entity. Defaults to true unless an initial acceleration is left unset.

Default: true

activeVelocity

Boolean

Defined in activeVelocity:102

Whether this motion should apply acceleration to the entity.

Default: true

controlState

String

Defined in controlState:120

When this state on the entity changes, this motion's active state is changed to match. If an "event" property is also set on this component, both the event and the state must be true for the motion to be active.

Default: ""

instant

Boolean

Defined in instant:129

Available since 0.6.7

If instant or instantState are set, the motion is only triggered for a single step and must be re-triggered to activate again. When the instantState on the entity becomes true, this motion's active state is changed to match. If an "instantState" property is also set on this component, both the event and the state must be true for the motion to be active.

Default: false

instantDecay

Number

Defined in instantDecay:157

This determines if setting active to false (via the control event or state) should dampen velocity. This is a ratio applied to the vector magnitude between 0 and 1. This is useful for events like jumping where a longer keypress should jump farther than a shorter keypress.

Default: null

instantState

String

Defined in instantState:139

If instant or instantState are set, the motion is only triggered for a single step and must be re-triggered to activate again. When the instantState on the entity becomes true, this motion's active state is changed to match. If an "instant" property is also set on this component, both the event and the state must be true for the motion to be active. If "event" or "controlState" are also defined, they must also be true to trigger an instant motion on the entity.

Default: ""

instantSuccess

String

Defined in instantSuccess:148

If instantState is set, this event is triggered when the intance of motion occurs on the entity.

Default: ""

maxMagnitude

Number

Defined in maxMagnitude:111

This is the highest magnitude allowed for the motion vector.

Default: Infinity

orient

Boolean

Defined in orient:74

Whether this motion should automatically re-orient when the entity re-orients.

Default: true

velocity

platypus.Vector | Array | Number

Defined in velocity:166

Available since 0.6.8

A vector, Array, or number specifying the direction and magnitude of the motion. Numbers apply magnitude along the x-axis. Arrays map to [x, y, z] on the vector.

Default: Vector(0, 0, 0)