API Documentation for: 0.11.8
Show:

platypus.components.CollisionTiles Class

This component causes the tile-map to collide with other entities. It must be part of a collision group and will cause "hit-by-tile" messages to fire on colliding entities.

Methods

'transform'

(
  • [transform]
)

Defined in 'transform':334

Performs a transform of a subset of the collision tile grid.

Parameters:

  • [transform] Object optional

    A list of key/value pairs describing the transform.

    • [type="horizontal"] String optional

      The type of transform; one of the following: "horizontal", "vertical", "diagonal", "diagonal-inverse", "rotate-90", "rotate-180", "rotate-270". Height and width should match for diagonal flips and 90 degree rotations.

    • [left=0] Number optional

      Grid coordinate for the left side of the bounding box.

    • [top=0] Number optional

      Grid coordinate for the top of the bounding box.

    • [width=grid.width] Number optional

      Cell width of the bounding box.

    • [height=grid.height] Number optional

      Cell height of the bounding box.

'translate'

(
  • [translate]
)

Defined in 'translate':349

Performs a translation of a subset of the collision tile grid.

Parameters:

  • [translate] Object optional

    A list of key/value pairs describing the translation.

    • [dx=0] Number optional

      Movement in columns.

    • [dy=0] Number optional

      Movement in rows.

    • [left=0] Number optional

      Grid coordinate for the left side of the bounding box.

    • [top=0] Number optional

      Grid coordinate for the top of the bounding box.

    • [width=grid.width] Number optional

      Cell width of the bounding box.

    • [height=grid.height] Number optional

      Cell height of the bounding box.

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.

getAABB

() platypus.AABB

Defined in getAABB:446

Returns the axis-aligned bounding box of the entire map.

Returns:

platypus.AABB:

aabb The returned object provides the top, left, width, and height of the collision map.

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.

getCollisionMatrix

(
  • originX
  • originY
  • width
  • height
)
Array

Gets a subset of the collision tile grid as a 2D array.

Parameters:

  • originX Number

    Grid coordinate for the left side of the bounding box.

  • originY Number

    Grid coordinate for the top of the bounding box.

  • width Number

    Cell width of the bounding box.

  • height Number

    Cell height of the bounding box.

Returns:

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.

getTileShapes

(
  • aabb
  • prevAABB
  • [collisionType]
)
Array

Defined in getTileShapes:468

Returns all the collision tiles within the provided axis-aligned bounding box as an array of shapes.

Parameters:

  • aabb platypus.AABB

    The axis-aligned bounding box for which tiles should be returned.

  • prevAABB platypus.AABB

    The axis-aligned bounding box for a previous location to test for jump-through tiles.

  • [collisionType] String optional

    The type of collision to check for. If not specified, "tiles" is used. (Since 0.8.3)

Returns:

Array:

Each returned object provides the CollisionShape of a tile.

isTile

(
  • x
  • y
)
Boolean

Defined in isTile:456

Confirms whether a particular map grid coordinate contains a tile.

Parameters:

  • x Number

    Integer specifying the column of tiles in the collision map to check.

  • y Number

    Integer specifying the row of tiles in the collision map to check.

Returns:

Boolean:

Returns true if the coordinate contains a collision tile, false if it does not.

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.

setCollisionMatrix

(
  • sourceArray
  • originX
  • originY
  • width
  • height
)

Sets a subset of the collision tile grid.

Parameters:

  • sourceArray Array

    A 2D array describing the collision tiles to insert into the collision tile grid.

  • originX Number

    Grid coordinate for the left side of the bounding box.

  • originY Number

    Grid coordinate for the top of the bounding box.

  • width Number

    Cell width of the bounding box.

  • height Number

    Cell height of the bounding box.

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

transform

(
  • [transform]
)

Defined in transform:503

Performs a transform of a subset of the collision tile grid.

Parameters:

  • [transform] Object optional

    A list of key/value pairs describing the transform.

    • [type="horizontal"] String optional

      The type of transform; one of the following: "horizontal", "vertical", "diagonal", "diagonal-inverse", "rotate-90", "rotate-180", "rotate-270". Height and width should match for diagonal flips and 90 degree rotations.

    • [left=0] Number optional

      Grid coordinate for the left side of the bounding box.

    • [top=0] Number optional

      Grid coordinate for the top of the bounding box.

    • [width=grid.width] Number optional

      Cell width of the bounding box.

    • [height=grid.height] Number optional

      Cell height of the bounding box.

translate

(
  • [translate]
)

Defined in translate:529

Performs a translation of a subset of the collision tile grid.

Parameters:

  • [translate] Object optional

    A list of key/value pairs describing the translation.

    • [dx=0] Number optional

      Movement in columns.

    • [dy=0] Number optional

      Movement in rows.

    • [left=0] Number optional

      Grid coordinate for the left side of the bounding box.

    • [top=0] Number optional

      Grid coordinate for the top of the bounding box.

    • [width=grid.width] Number optional

      Cell width of the bounding box.

    • [height=grid.height] Number optional

      Cell height of the bounding box.

Properties

collisionMap

Array

Defined in collisionMap:277

A 2D array describing the tile-map with off (0) and on (!0) states. The indexes match Tiled map data indexes with an additional bit setting (0x2000000) for jumpthrough tiles. Example: [[0, 0, 0], [1, 0, 0], [1, 1, 1]]. Available on the entity as entity.collisionMap.

Default: []

collisionType

String

Defined in collisionType:245

Available since 0.8.3

Sets the default collision type for non-zero map tiles.

Default: "tiles"

collisionTypeMap

Object

Defined in collisionTypeMap:235

Available since 0.8.3

Maps tile indexes to particular collision types. This defaults to a "tiles" collision type for all non-zero values if a particular collision map is not provided.

Default: null

left

Number

Defined in left:265

Available since 0.7.5

The map's left offset.

Default: 0

tileWidth

Number

Defined in tileWidth:286

The width of tiles in world coordinates. Available on the entity as entity.tileWidth.

Default: 10

tileWidth

Number

Defined in tileWidth:295

The height of tiles in world coordinates. Available on the entity as entity.tileHeight.

Default: 10

top

Number

Defined in top:255

Available since 0.7.5

The map's top offset.

Default: 0