Class: LineCollider
physics/collider/line.LineCollider
Represents a box in 2D space with a position and dimensions.
Hierarchy
Implements
Constructors
constructor
โข new LineCollider(start
, end
, weight
)
Create a Line with a start and end point.
All values are in world space, including weight.
Parameters
Name | Type | Description |
---|---|---|
start | vec2 | The start point of the line |
end | vec2 | The end point of the line |
weight | number | The weight of the line's stroke (thickness) |
Inherited from
Defined in
src/shapes/line.ts:27
โข new LineCollider(start
, direction
, length
, weight
)
Create a Line with a start and end point.
All values are in world space, including weight.
Parameters
Name | Type |
---|---|
start | vec2 |
direction | vec2 |
length | number |
weight | number |
Inherited from
Defined in
src/shapes/line.ts:29
โข new LineCollider(start
, angle
, length
, weight
)
Create a Line with a start and end point.
All values are in world space, including weight.
Parameters
Name | Type |
---|---|
start | vec2 |
angle | number |
length | number |
weight | number |
Inherited from
Defined in
src/shapes/line.ts:31
Properties
listeners
โข Protected
listeners: Object
= {}
Index signature
โช [index: string
]: Listener
[]
Implementation of
Collider.listeners
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)
Implementation of
Collider.opacity
Inherited from
Defined in
src/shapes/shape.ts:28
texture
โข texture: Texture
= defaultTexture
Implementation of
Collider.texture
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
Implementation of
Collider.addEventListener
Inherited from
Defined in
src/object2d.ts:209
findFurthestNeighbours
โธ 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 |
furthestIndex | number |
left | vec2 |
leftIndex | number |
right | vec2 |
rightIndex | number |
Implementation of
Collider.findFurthestNeighbours
Defined in
src/physics/collider/line.ts:81
findFurthestPoint
โธ 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
Implementation of
Collider.findFurthestPoint
Defined in
src/physics/collider/line.ts:59
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
Implementation of
Collider.fireEvent
Inherited from
Defined in
src/object2d.ts:185
getBaseVertices
โธ getBaseVertices(): vec2
[]
Calculates the base vertices of the rectangle.
These vertices are the base vertices for a quad, scaled to the width and height of the {@link Rectangle} instance.
Returns
vec2
[]
The rectangles base vertices
Implementation of
Collider.getBaseVertices
Inherited from
Defined in
src/shapes/rect.ts:84
getEnd
โธ getEnd(): vec2
Gets the point at which the line ends.
Returns
vec2
The end point of the line
Inherited from
Defined in
src/shapes/line.ts:127
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
Implementation of
Collider.getEventListeners
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
Implementation of
Collider.getEvents
Inherited from
Defined in
src/object2d.ts:175
getHeight
โธ getHeight(): number
Gets the rectangle's height in world space units.
Returns
number
The rectangle's height in world space
Inherited from
Defined in
src/shapes/rect.ts:162
getIndices
โธ getIndices(offset?
): Uint16Array
Gets the rect's vertex indices for drawing using element arrays.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
offset | number | 0 | An offset to apply to each index |
Returns
Uint16Array
The rect's vertex indices with the given offset added to each index
Implementation of
Collider.getIndices
Inherited from
Defined in
src/shapes/rect.ts:109
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
Implementation of
Collider.getPoints
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
Implementation of
Collider.getPosition
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
Implementation of
Collider.getRotation
Inherited from
Defined in
src/object2d.ts:139
getStart
โธ getStart(): vec2
Gets the point at which the line begins.
Returns
vec2
The start point of the line
Inherited from
Defined in
src/shapes/line.ts:109
getUVCoords
โธ getUVCoords(): Float32Array
Calculates the rects's UV coords to be used for texture rendering.
Returns
Float32Array
the rect's UV coords
Implementation of
Collider.getUVCoords
Inherited from
Defined in
src/shapes/rect.ts:118
getVertices
โธ getVertices(): number
[]
Calculates the shape's vertices in local space.
Returns
number
[]
The shape's vertices
Implementation of
Collider.getVertices
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
Implementation of
Collider.getVerticesClipSpace
Inherited from
Defined in
src/shapes/shape.ts:87
getVerticesWorld
โธ getVerticesWorld(origin
, rotation?
, returnVecs?
): number
[] | vec2
[]
Calculates the rect's vertices relative to the provided origin in world space.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
origin | vec2 | undefined | The origin to calculate the vertices relative to, should be a world position |
rotation? | number | undefined | An optional world space rotation to apply to the vertices |
returnVecs | boolean | false | Wether or not to return the vertices as vec2s or raw numbers |
Returns
number
[] | vec2
[]
The rect's vertices relative to the provided origin in world space
Implementation of
Collider.getVerticesWorld
Inherited from
Defined in
src/shapes/rect.ts:51
getWeight
โธ getWeight(): number
Gets the weight of the line (thickness).
Returns
number
The stroke weight of the line
Inherited from
Defined in
src/shapes/line.ts:91
getWidth
โธ getWidth(): number
Gets the rectangle's width in world space units.
Returns
number
The rectangle's width in world space
Inherited from
Defined in
src/shapes/rect.ts:140
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
Implementation of
Collider.moveRight
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
Implementation of
Collider.moveUp
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
Implementation of
Collider.removeEventListener
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
Implementation of
Collider.render
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
Implementation of
Collider.rotate
Inherited from
Defined in
src/object2d.ts:148
setEnd
โธ setEnd(end
): void
Sets the end point of the line.
Parameters
Name | Type | Description |
---|---|---|
end | vec2 | The new end point of the line |
Returns
void
Inherited from
Defined in
src/shapes/line.ts:118
setHeight
โธ setHeight(height
): void
Sets the rectangle's height.
throws
When the the provided height is < 0
Parameters
Name | Type | Description |
---|---|---|
height | number | The rectangle's new height |
Returns
void
Inherited from
Defined in
src/shapes/rect.ts:151
setPosition
โธ setPosition(pos
): void
Sets the object's position.
Parameters
Name | Type | Description |
---|---|---|
pos | vec2 | The object's new position |
Returns
void
Implementation of
Collider.setPosition
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
Implementation of
Collider.setPositionX
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
Implementation of
Collider.setPositionY
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
Implementation of
Collider.setRotation
Inherited from
Defined in
src/object2d.ts:128
setStart
โธ setStart(start
): void
Sets the starting point of the line.
Parameters
Name | Type | Description |
---|---|---|
start | vec2 | The new starting point of the line |
Returns
void
Inherited from
Defined in
src/shapes/line.ts:100
setWeight
โธ setWeight(weight
): void
Sets the weight of the line (thickness).
Parameters
Name | Type | Description |
---|---|---|
weight | number | The new weight of the line |
Returns
void
Inherited from
Defined in
src/shapes/line.ts:79
setWidth
โธ setWidth(width
): void
Sets the rectangle's width.
throws
When the the provided width is < 0
Parameters
Name | Type | Description |
---|---|---|
width | number | The rectangle's new width |
Returns
void
Inherited from
Defined in
src/shapes/rect.ts:129
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
Implementation of
Collider.setupEvents
Inherited from
Defined in
src/object2d.ts:165
supportPoint
โธ 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
Implementation of
Collider.supportPoint
Defined in
src/physics/collider/line.ts:44
testCollision
โธ testCollision(c
): CollisionResult
Checks if this line is colliding with another collider.
Parameters
Name | Type | Description |
---|---|---|
c | Collider | Collider to test collisions against |
Returns
CollisionResult with the results of the test
Implementation of
Collider.testCollision
Defined in
src/physics/collider/line.ts:18
translate
โธ translate(v
): void
Translates the object by the provided vector.
Parameters
Name | Type | Description |
---|---|---|
v | vec2 | The vector to translate by |
Returns
void
Implementation of
Collider.translate
Inherited from
Defined in
src/object2d.ts:91