API Documentation for: 0.11.8
Show:

platypus.components.Mover Class

This component handles entity motion via velocity and acceleration changes. This is useful for directional movement, gravity, bounce-back collision reactions, jumping, etc.

Methods

'component-added'

(
  • component
)

When a "Motion" component is added, this component adds it to its list of movers.

Parameters:

  • component "Motion" Component

    The motion to add as a mover on this entity.

'component-removed'

(
  • component
)

When a "Motion" component is removed, this component removes it from its list of movers.

Parameters:

  • component "Motion" Component

    The motion to remove as a mover from this entity.

'handle-movement'

(
  • tick
)

Defined in 'handle-movement':350

Available since 0.6.8

On each "handle-movement" event, this component moves the entity according to the list of movers on the entity.

Parameters:

  • tick Object
    • delta Number

      The amount of time in milliseconds since the last tick.

'hit-solid'

(
  • collisionInfo
)

Defined in 'hit-solid':408

On receiving this message, this component stops all velocities along the axis of the collision direction and sets "grounded" to true if colliding with the ground.

Parameters:

'load'

()

Defined in 'load':287

This component listens for a "load" event before setting up its mover list.

'orientation-updated'

(
  • matrix
)

Defined in 'orientation-updated':538

Available since 0.7.3

Handles velocity change if velocities should not be re-oriented.

Parameters:

  • matrix Array

    A 3x3 matrix describing the orientation change.

'pause-movment'

()

Defined in 'pause-movment':518

Available since 0.6.8

Stops all movement on the Entity.

'set-mover'

(
  • mover
)

Defined in 'set-mover':499

Available since 0.6.8

Update mover properties.

Parameters:

  • mover Object
    • [maxMagnitude] Number | Object optional

      New maximums for magnitude.

    • [magnitude] Number optional

      Delta for the change in maximums.

'unpause-movment'

()

Defined in 'unpause-movment':528

Available since 0.6.8

Unpauses all movement 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.

addMover

(
  • mover
)
"Motion" Component

Defined in addMover:574

This method adds a mover to the entity in the form of a "Motion" component definition.

Parameters:

  • mover Object

    For motion definition properties, see the "Motion" component.

Returns:

"Motion" Component:

motion

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.

removeMover

(
  • motion
)

Defined in removeMover:587

This method removes a mover from the entity.

Parameters:

  • motion "Motion" Component

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

drag

Number

Defined in drag:114

This property determines how quickly velocity is dampened when the entity is not in a "grounded" state. This should be a value between 1 (no motion) and 0 (no drag).

Default: 0.01

friction

Number

Defined in friction:123

This property determines how quickly velocity is dampened when the entity is in a "grounded" state. This should be a value between 1 (no motion) and 0 (no friction).

Default: 0.06

gravity

Number | Array | Vector

Defined in gravity:87

If specified, the property adds gravity motion to the entity.

Default: : 0

ground

Array | Vector

Defined in ground:68

Default: Vector(0, 1)

jump

Number | Array | Vector

Defined in jump:96

If specified, the property adds jumping motion to the entity.

Default: : 0

maxMagnitude

Number | Object

Defined in maxMagnitude:132

This property determines the maximum amount of velocity this entity can maintain. This can be a number or an object describing maximum velocity in a particular direction. For example:

{
                                                "up": 8,
                                                "right": 12,
                                                "down": 0.4,
                                                "left": 12
                                            }

Default: Infinity

maxMagnitudeDelta

Number

This property determines the rate of change to new maximum amount of velocities.

Default: 0

movers

Array

Defined in movers:78

A list of key/value pairs describing vectors or vector-like objects describing acceleration and velocity on the entity. See the "Motion" component for properties.

Default: []

reorientVelocities

Boolean

This property determines whether orientation changes should apply external velocities from pre-change momentum.

Default: true

speed

Number | Array | Vector

Defined in speed:105

If specified, the property adds velocity to the entity.

Default: : 0