Class: Collider
physics/collider/collider.Collider
Represents a collider (bounding box) in 2D space.
Collider's should always be positioned in world space so that collisions can be calculated correctly.
Hierarchy
โณ
Collider
Implemented by
Constructors
constructor
โข new Collider()
Inherited from
Defined in
src/shapes/shape.ts:30
Properties
listeners
โข Protected
listeners: Object
= {}
Index signature
โช [index: string
]: Listener
[]
Inherited from
Defined in
src/object2d.ts:32
opacity
โข opacity: number
= 1
Opacity of the shape.
This is an opacity of the whole shape which is applied to the shape's entire texture equally.
Range is 0 (completely transparent) to 1 (completely opaque)
Inherited from
Defined in
src/shapes/shape.ts:28
texture
โข texture: Texture
= defaultTexture
Inherited from
Defined in
src/shapes/shape.ts:19
Methods
addEventListener
โธ addEventListener(event
, listener
): boolean
Executes a function when an event is fired.
Parameters
Name | Type | Description |
---|---|---|
event | string | The event to listen for |
listener | Listener | The function to execute when the event fired |
Returns
boolean
Wether or not the listener was added
Inherited from
Defined in
src/object2d.ts:209
findFurthestNeighbours
โธ Abstract
findFurthestNeighbours(direction
): Object
Calculates the furthest point on the collider in a direction and it's neighbouring vertices on the collider.
Parameters
Name | Type | Description |
---|---|---|
direction | vec2 | The direction in which to calculate the furthest point |
Returns
Object
The furthest point on the collider in the given direction and its left and right neighbours
Name | Type |
---|---|
furthest | vec2 |
left | vec2 |
leftIndex? | number |
right | vec2 |
rightIndex? | number |
Defined in
src/physics/collider/collider.ts:56
findFurthestPoint
โธ Abstract
findFurthestPoint(direction
): vec2
Calculates the furthest point on the collider in a direction.
Parameters
Name | Type | Description |
---|---|---|
direction | vec2 | The direction in which to calculate the furthest point |
Returns
vec2
The furthest point on the collider in the given direction
Defined in
src/physics/collider/collider.ts:48
fireEvent
โธ fireEvent(event
, ...e
): void
Executes all listeners attached to a given event.
Parameters
Name | Type | Description |
---|---|---|
event | string | The event to fire |
...e | any | The data to pass to each event listener |
Returns
void
Inherited from
Defined in
src/object2d.ts:185
getBaseVertices
โธ Abstract
getBaseVertices(): vec2
[]
Calculates the base vertices of the shape.
These are the vertices for the type of shape at unit size, scaled to the shape's dimensions.
Returns
vec2
[]
The shape's vertices
Inherited from
Defined in
src/shapes/shape.ts:109
getEventListeners
โธ getEventListeners(event
): Listener
[]
Gets the listeners attached to an event.
Parameters
Name | Type |
---|---|
event | string |
Returns
Listener
[]
An array of listeners attached to the given event
Inherited from
Defined in
src/object2d.ts:198
getEvents
โธ getEvents(): string
[]
Gets the events that can be listened to on the object.
Returns
string
[]
The events the object supports
Inherited from
Defined in
src/object2d.ts:175
getIndices
โธ Abstract
getIndices(offset?
): Uint16Array
Gets the shape's vertex indices for drawing using element arrays.
Parameters
Name | Type | Description |
---|---|---|
offset? | number | An offset to apply to each index |
Returns
Uint16Array
The shape's vertex indices with the given offset added to each index
Inherited from
Defined in
src/shapes/shape.ts:117
getPoints
โธ getPoints(): vec2
[]
Calculates the bounding points of the Shape instance.
NOTE: The shape's vertices are recalculated every time this function is called.
Returns
vec2
[]
The bounding points of the box
Inherited from
Defined in
src/shapes/shape.ts:136
getPosition
โธ getPosition(): vec2
Gets the object's position.
Returns
vec2
The object's position as a vec2
Inherited from
Defined in
src/object2d.ts:82
getRotation
โธ getRotation(): number
Gets the object's rotation as a number in radians relative to y+.
Returns
number
The object's rotation
Inherited from
Defined in
src/object2d.ts:139
getUVCoords
โธ Abstract
getUVCoords(): Float32Array
Calculates the shape's UV coords to be used for texture rendering.
Returns
Float32Array
the shape's UV coords
Inherited from
Defined in
src/shapes/shape.ts:50
getVertices
โธ getVertices(): number
[]
Calculates the shape's vertices in local space.
Returns
number
[]
The shape's vertices
Inherited from
Defined in
src/shapes/shape.ts:57
getVerticesClipSpace
โธ getVerticesClipSpace(origin
, scale
, rotation?
, camera?
): number
[]
Calculates the shape's vertices relative to the provided origin in world space.
Parameters
Name | Type | Description |
---|---|---|
origin | vec2 | The origin to calculate the vertices relative to, should be a world position |
scale | vec2 | The vector to scale the world space vertices by to obtain clip space values |
rotation? | number | An optional rotation to apply to the vertices |
camera? | Camera | An optional camera to get vertices relative to |
Returns
number
[]
The shape's vertices relative to the provided origin in clip space
Inherited from
Defined in
src/shapes/shape.ts:87
getVerticesWorld
โธ Abstract
getVerticesWorld(origin
, rotation?
, returnVecs?
): number
[] | vec2
[]
Calculates the shape's vertices relative to the provided origin in world space.
Parameters
Name | Type | Description |
---|---|---|
origin | vec2 | The origin to calculate the vertices relative to, should be a world position |
rotation? | number | An optional world space rotation to apply to the vertices |
returnVecs? | boolean | Wether or not to return the vertices as vec2s or raw numbers |
Returns
number
[] | vec2
[]
The shape's vertices relative to the provided origin in world space
Inherited from
Defined in
src/shapes/shape.ts:76
moveRight
โธ moveRight(dist
): void
Moves the object's position right (x+) relative to it's rotation.
Parameters
Name | Type | Description |
---|---|---|
dist | number | The distance to move right, can be + or - |
Returns
void
Inherited from
Defined in
src/object2d.ts:100
moveUp
โธ moveUp(dist
): void
Moves the object's position up (y+) relative to it's rotation.
Parameters
Name | Type | Description |
---|---|---|
dist | number | The distance to move up, can be + or - |
Returns
void
Inherited from
Defined in
src/object2d.ts:114
removeEventListener
โธ removeEventListener(event
, listener
): boolean
Removes a listener from an event.
Parameters
Name | Type | Description |
---|---|---|
event | string | The event the listener is attached to |
listener | Listener | The listener to remove |
Returns
boolean
Wether or not the listener was removed
Inherited from
Defined in
src/object2d.ts:223
render
โธ render(position?
, rotation?
, zIndex?
): void
Renders the shape using the Renderer.
Parameters
Name | Type | Description |
---|---|---|
position? | vec2 | The x and y position to render the shape at |
rotation? | number | The rotation to apply to the rendered shape |
zIndex? | number | The z position of the rendered shape |
Returns
void
Inherited from
Defined in
src/shapes/shape.ts:41
rotate
โธ rotate(angle
): void
Increments the object's rotation by an angle in radians.
Parameters
Name | Type | Description |
---|---|---|
angle | number | The angle to rotate by in radians |
Returns
void
Inherited from
Defined in
src/object2d.ts:148
setPosition
โธ setPosition(pos
): void
Sets the object's position.
Parameters
Name | Type | Description |
---|---|---|
pos | vec2 | The object's new position |
Returns
void
Inherited from
Defined in
src/object2d.ts:43
setPositionX
โธ setPositionX(x
): void
Sets the x component of the object's position.
Parameters
Name | Type | Description |
---|---|---|
x | number | The object's new x coordinate |
Returns
void
Inherited from
Defined in
src/object2d.ts:56
setPositionY
โธ setPositionY(y
): void
Sets the y component of the object's position.
Parameters
Name | Type | Description |
---|---|---|
y | number | The object's new y coordinate |
Returns
void
Inherited from
Defined in
src/object2d.ts:69
setRotation
โธ setRotation(angle
): void
Sets the object's rotation.
Parameters
Name | Type | Description |
---|---|---|
angle | number | The object's new rotation |
Returns
void
Inherited from
Defined in
src/object2d.ts:128
setupEvents
โธ Protected
setupEvents(): void
Sets all the events that can be used in listeners
.
Listeners can be added for an event using:
this.listeners.eventName = [];
example
Setup listeners for "position" and "rotate" events.
this.listeners.position = [];
this.listeners.rotate = [];
Returns
void
Inherited from
Defined in
src/object2d.ts:165
supportPoint
โธ Abstract
supportPoint(c
, direction
): vec2
Calculates a support point on the minkowski difference in a given direction.
Parameters
Name | Type | Description |
---|---|---|
c | Collider | The collider to test against |
direction | vec2 | The direction to use when calculating furthest points |
Returns
vec2
The support point in the given direction for the Minkowski difference
Defined in
src/physics/collider/collider.ts:40
testCollision
โธ Abstract
testCollision(c
): CollisionResult
Checks if this collider is colliding with another collider.
Parameters
Name | Type | Description |
---|---|---|
c | Collider | Collider to test collisions against |
Returns
CollisionResult with the results of the test
Defined in
src/physics/collider/collider.ts:31
translate
โธ translate(v
): void
Translates the object by the provided vector.
Parameters
Name | Type | Description |
---|---|---|
v | vec2 | The vector to translate by |
Returns
void
Inherited from
Defined in
src/object2d.ts:91