API Documentation for: 0.11.8
Show:

platypus.components.CollisionBasic Class

This component causes this entity to collide with other entities. It must be part of a collision group and will receive messages when colliding with other entities in the collision group.

Multiple collision components may be added to a single entity if distinct messages should be triggered for certain collision areas on the entity or if the soft collision area is a different shape from the solid collision area. Be aware that too many additional collision areas may adversely affect performance.

Methods

'collide-off'

(
  • type
)

Defined in 'collide-off':549

On receiving this message, the component triggers remove-collision-entity on the parent.

Parameters:

  • type String

    If specified, only collision components of this type are removed from the collision list.

'collide-on'

(
  • type
)

Defined in 'collide-on':523

On receiving this message, the component triggers add-collision-entity on the parent.

Parameters:

  • type String

    If specified, only collision components of this type are added to the collision list.

'handle-logic'

()

Defined in 'handle-logic':644

If the entity is stuck to another entity, this component tries to unstick the entity on each logic step.

'orientation-updated'

(
  • matrix
)

Collision shapes are updated to reflect the new orientation when this message occurs.

Parameters:

  • matrix Array

    A 2D matrix describing the new orientation.

'relocate-entity'

(
  • position
)

This message causes the entity's x,y coordinates to update.

Parameters:

  • position platypus.Vector

    The new coordinates.

    • [relative=false] Boolean optional

      Determines whether the provided x,y coordinates are relative to the entity's current position.

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

bullet

Boolean

Defined in bullet:392

Whether this entity should be tested across its entire movement path. This is necessary for fast-moving entities, but shouldn't be used for others due to the processing overhead. Available on the entity as entity.bullet.

Default: false

collisionType

String

Defined in collisionType:262

Defines how this entity should be recognized by other colliding entities.

Default: "none"

height

Number

Defined in height:316

Sets the height of the collision area in world coordinates.

Default: 0

ignoreOrientation

Boolean

Determines whether the collision area should transform on orientation changes.

Default: false

immobile

Boolean

Defined in immobile:383

This property should be set to true if entity doesn't move for better optimization. This causes other entities to check against this entity, but this entity performs no checks of its own. Available on the entity as entity.immobile.

Default: false

jumpThrough

Boolean

Defined in jumpThrough:401

Whether the entity is only solid when being collided with from the top.

Default: : false

margin

Number | Object

Defined in margin:363

This is the margin around the entity's width and height. This is an alternative method for specifying the collision shape in terms of the size of the entity. Can also pass in an object specifying the following parameters if the margins vary per side: top, bottom, left, and right.

Default: 0

radius

Number

Defined in radius:325

Sets the radius of a circle collision area in world coordinates.

Default: 0

regX

Number

Defined in regX:289

Determines the x-axis center of the collision shape.

Default: width / 2

regY

Number

Defined in regY:298

Determines the y-axis center of the collision shape.

Default: height / 2

shapes

Array

Defined in shapes:372

Defines one or more shapes to create the collision area. Defaults to a single shape with the width, height, regX, and regY properties of the entity if not specified. See CollisionShape for the full list of properties.

Default: null

shapeType

String

Defined in shapeType:271

Defines the type of colliding shape.

Default: "rectangle"

softCollisions

Object

Defined in softCollisions:334

Determines which collision types this entity should consider soft, meaning this entity may pass through them, but triggers collision messages on doing so. Example:

{
                                                "water": "soaked",       // This triggers a "soaked" message on the entity when it passes over a "water" collision-type entity.
                                                "lava": ["burn", "ouch"] // This triggers both messages on the entity when it passes over a "lava" collision-type entity.
                                            }

Default: null

solidCollisions

Object

Defined in solidCollisions:348

Determines which collision types this entity should consider solid, meaning this entity should not pass through them. Example:

{
                                                "boulder": "",                       // This specifies that this entity should not pass through other "boulder" collision-type entities.
                                                "diamond": "crack-up",               // This specifies that this entity should not pass through "diamond" collision-type entities, but if it touches one, it triggers a "crack-up" message on the entity.
                                                "marble": ["flip", "dance", "crawl"] // This specifies that this entity should not pass through "marble" collision-type entities, but if it touches one, it triggers all three specified messages on the entity.
                                            }

Default: null

width

Number

Defined in width:307

Sets the width of the collision area in world coordinates.

Default: 0

Events

'add-collision-entity'

On receiving 'collide-on', this message is triggered on the parent to turn on collision.

Event Payload:

'remove-collision-entity'

On receiving 'collide-off', this message is triggered on the parent to turn off collision.

Event Payload:

*

Defined in *:20

On receiving a 'hit-by' message, custom messages are triggered on the entity corresponding with the component's solidCollisions and softCollisions key/value mappings.

Event Payload:

  • collision Object

    A list of key/value pairs describing the collision.