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.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
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:
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.
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. |