API Documentation for: 0.11.8
Show:

platypus.components.HandlerCollision Class

This component checks for collisions between entities which typically have either a CollisionTiles component for tile maps or a CollisionBasic component for other entities. It uses EntityContainer component messages if triggered to add to its collision list and also listens for explicit add/remove messages (useful in the absence of an EntityContainer component).

Methods

'add-collision-entity'

(
  • entity
)

On receiving this message, the component checks the entity to determine whether it listens for collision messages. If so, the entity is added to the collision group.

Parameters:

  • entity Entity

    The entity to be added.

'check-collision-group'

(
  • options
)

This message causes the component to go through the entities and check for collisions.

Parameters:

  • options Object
    • [camera] Object optional

      Specifies a region in which to check for collisions. Expects the camera object to contain the following properties: top, left, width, height, and buffer.

'child-entity-added'

(
  • entity
)

On receiving this message, the component checks the entity to determine whether it listens for collision messages. If so, the entity is added to the collision group.

Parameters:

  • entity Entity

    The entity to be added.

'child-entity-removed'

(
  • message
)

On receiving this message, the component looks for the entity in its collision group and removes it.

Parameters:

'child-entity-updated'

(
  • message
)

On receiving this message, the component looks for the entity in its collision group and updates it.

Parameters:

'remove-collision-entity'

(
  • message
)

On receiving this message, the component looks for the entity in its collision group and removes it.

Parameters:

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.

getEntityCollisions

(
  • entity
)
Array

This method returns a list of collision objects describing soft collisions between an entity and a list of other entities.

Parameters:

  • entity Entity

    The entity to test against the world.

Returns:

Array:

collisions This is a list of collision objects describing the soft collisions.

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.

getPointCollisions

(
  • x
  • y
  • collisionTypes
)
Array

Defined in getPointCollisions:1254

Available since 0.11.0

This method returns a list of collision objects describing collisions between a point and a list of other entities.

Parameters:

  • x Number

    The x-axis value.

  • y Number

    The y-axis value.

  • collisionTypes Array of strings

    The collision types to check against.

Returns:

Array:

collisions This is a list of collision objects describing the soft collisions.

getShapeCollisions

(
  • shape
  • collisionTypes
)
Array

Defined in getShapeCollisions:1235

Available since 0.11.2

This method returns a list of collision objects describing collisions between a shape and a list of other entities.

Parameters:

  • shape CollisionShape

    The shape to check for collisions.

  • collisionTypes Array of strings

    The collision types to check against.

Returns:

Array:

collisions This is a list of collision objects describing the soft collisions.

getWorldEntities

() Array

This method returns an object containing world entities.

Returns:

Array:

A list of all world collision entities.

getWorldTerrain

() Entity

This method returns an entity representing the collision map of the world.

Returns:

Entity:
  • An entity describing the collision map of the world. This entity typically includes a CollisionTiles component.

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]".

Events

'hit-by-*'

Defined in 'hit-by-*':14

When an entity collides with an entity of a listed collision-type, this message is triggered on the entity. * is the other entity's collision-type.

Event Payload:

  • collision Object
    • entity Entity

      The entity with which the collision occurred.

    • target Entity

      The entity that's receiving the collision event.

    • type String

      The collision type of the other entity.

    • shape CollisionShape

      This is the shape of the other entity that caused the collision.

    • x Number

      Returns -1, 0, or 1 indicating on which side of this entity the collision occurred: left, neither, or right respectively.

    • y Number

      Returns -1, 0, or 1 indicating on which side of this entity the collision occurred: top, neither, or bottom respectively.

'relocate-entity'

This message is triggered on an entity that has been repositioned due to a solid collision.

Event Payload:

  • object Object
    • position Vector

      The relocated position of the entity.