CollisionShape

platypus. CollisionShape

new CollisionShape(owner, definition, collisionType)

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.

Source:
Parameters:
Name Type Description
owner platypus.Entity

The entity that uses this shape.

definition Object

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

Name Type Attributes Default Description
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 String <optional>
"rectangle"

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

(static) recycle(The)

Returns a CollisionShape back to the cache.

Source:
Parameters:
Name Type Description
The platypus.CollisionShape

CollisionShape to be recycled.

(static) setUp() → {platypus.CollisionShape}

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

Source:
Returns:
Type:
platypus.CollisionShape

The instantiated CollisionShape.

collides(shape) → {Boolean}

Determines whether shapes collide.

Source:
Parameters:
Name Type Description
shape platypus.CollisionShape

The shape to check against for collision.

Returns:
Type:
Boolean

Whether the shapes collide.

containsPoint(x, y) → {boolean}

Expresses whether this shape contains the given point.

Source:
Parameters:
Name Type Description
x number

The x-axis value.

y number

The y-axis value.

Returns:
Type:
boolean

Returns true if this shape contains the point.

getAABB() → {platypus.AABB}

Returns the axis-aligned bounding box of the shape.

Source:
Returns:
Type:
platypus.AABB

The AABB of the shape.

moveX(x)

Move the shape's x position.

Source:
Parameters:
Name Type Description
x number

The x position to which the shape should be moved.

moveXY(x, y)

Move the shape's x and y position.

Source:
Parameters:
Name Type Description
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)

Move the shape's y position.

Source:
Parameters:
Name Type Description
y number

The y position to which the shape should be moved.

multiply(matrix)

Transform the shape using a matrix transformation.

Source:
Parameters:
Name Type Description
matrix Array

A matrix used to transform the shape.

recycle()

Relinquishes properties of the CollisionShape and recycles it.

Source:

setXWithEntityX(entityX)

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

Source:
Parameters:
Name Type Description
entityX number

The x position of the entity.

setYWithEntityY(entityY)

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

Source:
Parameters:
Name Type Description
entityY number

The y position of the entity.

toJSON() → {Object}

Returns a JSON object describing the collision shape.

Source:
Returns:
Type:
Object

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

update(ownerX, ownerY)

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.

Source:
Parameters:
Name Type Description
ownerX number

The x position of the owner.

ownerY number

The y position of the owner.

updateAll(updateAll)

Updates the shape to match another shape.

Source:
Parameters:
Name Type Description
updateAll platypus.CollisionShape

The shape to copy into this one.