API Documentation for: 0.11.8
Show:

platypus.CollisionShape Class

Module: platypus

This class defines a collision shape, which defines the 'space' an entity occupies in the collision system. Currently only rectangle and circle shapes can be created. Collision shapes include an axis-aligned bounding box (AABB) that tightly wraps the shape. The AABB is used for initial collision checks.

Constructor

platypus.CollisionShape

(
  • owner
  • definition
  • collisionType
)

Parameters:

  • owner platypus.Entity

    The entity that uses this shape.

  • definition Object

    This is an object of key/value pairs describing the shape.

    • x Number

      The x position of the shape. The x is always located in the center of the object.

    • y Number

      The y position of the shape. The y is always located in the center of the object.

    • [type="rectangle"] String optional

      The type of shape this is. Currently this can be either "rectangle" or "circle".

    • [width] Number optional

      The width of the shape if it's a rectangle.

    • [height] Number optional

      The height of the shape if it's a rectangle.

    • [radius] Number optional

      The radius of the shape if it's a circle.

    • [offsetX] Number optional

      The x offset of the collision shape from the owner entity's location.

    • [offsetY] Number optional

      The y offset of the collision shape from the owner entity's location.

    • [regX] Number optional

      The registration x of the collision shape with the owner entity's location if offsetX is not provided.

    • [regY] Number optional

      The registration y of the collision shape with the owner entity's location if offsetX is not provided.

  • collisionType String

    A string describing the collision type of this shape.

Methods

collides

(
  • shape
)
Boolean

Defined in collides:83

Available since 0.7.4

Determines whether shapes collide.

Parameters:

Returns:

Boolean:

Whether the shapes collide.

CollisionShape.recycle

(
  • The
)

Defined in CollisionShape.recycle:286

Available since 0.7.4

Returns a CollisionShape back to the cache.

Parameters:

CollisionShape.setUp

() platypus.CollisionShape

Defined in CollisionShape.setUp:279

Available since 0.7.4

Returns an CollisionShape from cache or creates a new one if none are available.

Returns:

platypus.CollisionShape:

The instantiated CollisionShape.

containsPoint

(
  • x
  • y
)
Boolean

Defined in containsPoint:226

Available since 0.11.0

Expresses whether this shape contains the given point.

Parameters:

Returns:

Boolean:

Returns true if this shape contains the point.

getAABB

() platypus.AABB

Defined in getAABB:171

Returns the axis-aligned bounding box of the shape.

Returns:

platypus.AABB:

The AABB of the shape.

moveX

(
  • x
)

Defined in moveX:135

Move the shape's x position.

Parameters:

  • x Number

    The x position to which the shape should be moved.

moveXY

(
  • x
  • y
)

Defined in moveXY:157

Available since 0.11.2

Move the shape's x and y position.

Parameters:

  • x Number

    The x position to which the shape should be moved.

  • y Number

    The y position to which the shape should be moved.

moveY

(
  • y
)

Defined in moveY:146

Move the shape's y position.

Parameters:

  • y Number

    The y position to which the shape should be moved.

multiply

(
  • matrix
)

Defined in multiply:203

Transform the shape using a matrix transformation.

Parameters:

  • matrix Array

    A matrix used to transform the shape.

recycle

()

Defined in recycle:293

Available since 0.7.4

Relinquishes properties of the CollisionShape and recycles it.

setXWithEntityX

(
  • entityX
)

Defined in setXWithEntityX:181

Set the shape's position as if the entity's x position is in a certain location.

Parameters:

  • entityX Number

    The x position of the entity.

setYWithEntityY

(
  • entityY
)

Defined in setYWithEntityY:192

Set the shape's position as if the entity's y position is in a certain location.

Parameters:

  • entityY Number

    The y position of the entity.

toJSON

() Object

Defined in toJSON:244

Available since 0.11.0

Returns a JSON object describing the collision shape.

Returns:

Object:

Returns a JSON definition that can be used to recreate the collision shape.

update

(
  • ownerX
  • ownerY
)

Defined in update:120

Updates the location of the shape and AABB. The position you send should be that of the owner, the offset of the shape is added inside the function.

Parameters:

  • ownerX Number

    The x position of the owner.

  • ownerY Number

    The y position of the owner.